Esempio n. 1
0
        internal ReplicationNeighbor(IntPtr addr, DirectoryServer server, Hashtable table)
        {
            DS_REPL_NEIGHBOR neighbor = new DS_REPL_NEIGHBOR();
            Marshal.PtrToStructure(addr, neighbor);

            _namingContext = Marshal.PtrToStringUni(neighbor.pszNamingContext);
            _sourceServerDN = Marshal.PtrToStringUni(neighbor.pszSourceDsaDN);

            string transportDN = Marshal.PtrToStringUni(neighbor.pszAsyncIntersiteTransportDN);
            if (transportDN != null)
            {
                string rdn = Utils.GetRdnFromDN(transportDN);
                string transport = (Utils.GetDNComponents(rdn))[0].Value;

                if (String.Compare(transport, "SMTP", StringComparison.OrdinalIgnoreCase) == 0)
                    _transportType = ActiveDirectoryTransportType.Smtp;
                else
                    _transportType = ActiveDirectoryTransportType.Rpc;
            }

            _replicaFlags = (ReplicationNeighborOptions)neighbor.dwReplicaFlags;
            _uuidSourceDsaInvocationID = neighbor.uuidSourceDsaInvocationID;
            _usnLastObjChangeSynced = neighbor.usnLastObjChangeSynced;
            _usnAttributeFilter = neighbor.usnAttributeFilter;
            _timeLastSyncSuccess = DateTime.FromFileTime(neighbor.ftimeLastSyncSuccess);
            _timeLastSyncAttempt = DateTime.FromFileTime(neighbor.ftimeLastSyncAttempt);
            _lastSyncResult = neighbor.dwLastSyncResult;
            _consecutiveSyncFailures = neighbor.cNumConsecutiveSyncFailures;

            _server = server;
            _nameTable = table;
        }
Esempio n. 2
0
        internal ReplicationNeighbor(IntPtr addr, DirectoryServer server, Hashtable table)
        {
            DS_REPL_NEIGHBOR dSREPLNEIGHBOR = new DS_REPL_NEIGHBOR();

            Marshal.PtrToStructure(addr, dSREPLNEIGHBOR);
            this.namingContext  = Marshal.PtrToStringUni(dSREPLNEIGHBOR.pszNamingContext);
            this.sourceServerDN = Marshal.PtrToStringUni(dSREPLNEIGHBOR.pszSourceDsaDN);
            string stringUni = Marshal.PtrToStringUni(dSREPLNEIGHBOR.pszAsyncIntersiteTransportDN);

            if (stringUni != null)
            {
                string rdnFromDN = Utils.GetRdnFromDN(stringUni);
                string value     = Utils.GetDNComponents(rdnFromDN)[0].Value;
                if (string.Compare(value, "SMTP", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    this.transportType = ActiveDirectoryTransportType.Rpc;
                }
                else
                {
                    this.transportType = ActiveDirectoryTransportType.Smtp;
                }
            }
            this.replicaFlags = (ReplicationNeighbor.ReplicationNeighborOptions)((long)dSREPLNEIGHBOR.dwReplicaFlags);
            this.uuidSourceDsaInvocationID = dSREPLNEIGHBOR.uuidSourceDsaInvocationID;
            this.usnLastObjChangeSynced    = dSREPLNEIGHBOR.usnLastObjChangeSynced;
            this.usnAttributeFilter        = dSREPLNEIGHBOR.usnAttributeFilter;
            this.timeLastSyncSuccess       = DateTime.FromFileTime(dSREPLNEIGHBOR.ftimeLastSyncSuccess);
            this.timeLastSyncAttempt       = DateTime.FromFileTime(dSREPLNEIGHBOR.ftimeLastSyncAttempt);
            this.lastSyncResult            = dSREPLNEIGHBOR.dwLastSyncResult;
            this.consecutiveSyncFailures   = dSREPLNEIGHBOR.cNumConsecutiveSyncFailures;
            this.server    = server;
            this.nameTable = table;
        }
 public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
 {
     ValidateArgument(context, name);
     if (sourceServer == null)
     {
         throw new ArgumentNullException("sourceServer");
     }
     if ((transport < ActiveDirectoryTransportType.Rpc) || (transport > ActiveDirectoryTransportType.Smtp))
     {
         throw new InvalidEnumArgumentException("value", (int) transport, typeof(ActiveDirectoryTransportType));
     }
     context = new DirectoryContext(context);
     this.ValidateTargetAndSourceServer(context, sourceServer);
     this.context = context;
     this.connectionName = name;
     this.transport = transport;
     DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
     try
     {
         string str = (string) PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ServerName);
         string dn = "CN=NTDS Settings," + str;
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
         string escapedPath = Utils.GetEscapedPath("cn=" + this.connectionName);
         this.cachedDirectoryEntry = directoryEntry.Children.Add(escapedPath, "nTDSConnection");
         DirectoryContext context2 = sourceServer.Context;
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context2, WellKnownDN.RootDSE);
         string str4 = (string) PropertyManager.GetPropertyValue(context2, directoryEntry, PropertyManager.ServerName);
         str4 = "CN=NTDS Settings," + str4;
         this.cachedDirectoryEntry.Properties["fromServer"].Add(str4);
         if (schedule != null)
         {
             this.cachedDirectoryEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
         }
         string dNFromTransportType = Utils.GetDNFromTransportType(this.TransportType, context);
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dNFromTransportType);
         try
         {
             directoryEntry.Bind(true);
         }
         catch (COMException exception)
         {
             if (((exception.ErrorCode == -2147016656) && Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode)) && (transport == ActiveDirectoryTransportType.Smtp))
             {
                 throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
             }
             throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
         }
         this.cachedDirectoryEntry.Properties["transportType"].Add(dNFromTransportType);
         this.cachedDirectoryEntry.Properties["enabledConnection"].Value = false;
         this.cachedDirectoryEntry.Properties["options"].Value = 0;
     }
     catch (COMException exception2)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception2);
     }
     finally
     {
         directoryEntry.Close();
     }
 }
 internal ReplicationNeighbor(IntPtr addr, DirectoryServer server, Hashtable table)
 {
     DS_REPL_NEIGHBOR structure = new DS_REPL_NEIGHBOR();
     Marshal.PtrToStructure(addr, structure);
     this.namingContext = Marshal.PtrToStringUni(structure.pszNamingContext);
     this.sourceServerDN = Marshal.PtrToStringUni(structure.pszSourceDsaDN);
     string distinguishedName = Marshal.PtrToStringUni(structure.pszAsyncIntersiteTransportDN);
     if (distinguishedName != null)
     {
         if (string.Compare(Utils.GetDNComponents(Utils.GetRdnFromDN(distinguishedName))[0].Value, "SMTP", StringComparison.OrdinalIgnoreCase) == 0)
         {
             this.transportType = ActiveDirectoryTransportType.Smtp;
         }
         else
         {
             this.transportType = ActiveDirectoryTransportType.Rpc;
         }
     }
     this.replicaFlags = (ReplicationNeighborOptions) structure.dwReplicaFlags;
     this.uuidSourceDsaInvocationID = structure.uuidSourceDsaInvocationID;
     this.usnLastObjChangeSynced = structure.usnLastObjChangeSynced;
     this.usnAttributeFilter = structure.usnAttributeFilter;
     this.timeLastSyncSuccess = DateTime.FromFileTime(structure.ftimeLastSyncSuccess);
     this.timeLastSyncAttempt = DateTime.FromFileTime(structure.ftimeLastSyncAttempt);
     this.lastSyncResult = structure.dwLastSyncResult;
     this.consecutiveSyncFailures = structure.cNumConsecutiveSyncFailures;
     this.server = server;
     this.nameTable = table;
 }
Esempio n. 5
0
        internal ReplicationNeighbor(IntPtr addr, DirectoryServer server, Hashtable table)
        {
            DS_REPL_NEIGHBOR structure = new DS_REPL_NEIGHBOR();

            Marshal.PtrToStructure(addr, structure);
            this.namingContext  = Marshal.PtrToStringUni(structure.pszNamingContext);
            this.sourceServerDN = Marshal.PtrToStringUni(structure.pszSourceDsaDN);
            string distinguishedName = Marshal.PtrToStringUni(structure.pszAsyncIntersiteTransportDN);

            if (distinguishedName != null)
            {
                if (string.Compare(Utils.GetDNComponents(Utils.GetRdnFromDN(distinguishedName))[0].Value, "SMTP", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    this.transportType = ActiveDirectoryTransportType.Smtp;
                }
                else
                {
                    this.transportType = ActiveDirectoryTransportType.Rpc;
                }
            }
            this.replicaFlags = (ReplicationNeighborOptions)structure.dwReplicaFlags;
            this.uuidSourceDsaInvocationID = structure.uuidSourceDsaInvocationID;
            this.usnLastObjChangeSynced    = structure.usnLastObjChangeSynced;
            this.usnAttributeFilter        = structure.usnAttributeFilter;
            this.timeLastSyncSuccess       = DateTime.FromFileTime(structure.ftimeLastSyncSuccess);
            this.timeLastSyncAttempt       = DateTime.FromFileTime(structure.ftimeLastSyncAttempt);
            this.lastSyncResult            = structure.dwLastSyncResult;
            this.consecutiveSyncFailures   = structure.cNumConsecutiveSyncFailures;
            this.server    = server;
            this.nameTable = table;
        }
Esempio n. 6
0
 internal ActiveDirectoryInterSiteTransport(DirectoryContext context, ActiveDirectoryTransportType transport, DirectoryEntry entry)
 {
     this.siteLinkCollection = new ReadOnlySiteLinkCollection();
     this.bridgeCollection   = new ReadOnlySiteLinkBridgeCollection();
     this.context            = context;
     this.transport          = transport;
     this.cachedEntry        = entry;
 }
        internal ActiveDirectorySiteLinkBridge(DirectoryContext context, string bridgeName, ActiveDirectoryTransportType transport, bool existing)
        {
            this.context = context;
            _name        = bridgeName;
            _transport   = transport;

            _existing = existing;
        }
Esempio n. 8
0
 internal ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, bool existing, DirectoryEntry entry)
 {
     this.context     = context;
     _name            = siteLinkName;
     _transport       = transport;
     this.existing    = existing;
     this.cachedEntry = entry;
 }
 internal ActiveDirectorySiteLinkBridge(DirectoryContext context, string bridgeName, ActiveDirectoryTransportType transport, bool existing)
 {
     this.links     = new ActiveDirectorySiteLinkCollection();
     this.context   = context;
     this.name      = bridgeName;
     this.transport = transport;
     this.existing  = existing;
 }
    public static ActiveDirectoryInterSiteTransport FindByTransportType(DirectoryContext context, ActiveDirectoryTransportType transport)
    {
      Contract.Requires(context != null);

      Contract.Ensures(Contract.Result<ActiveDirectoryInterSiteTransport>() != null);

      return default(ActiveDirectoryInterSiteTransport);
    }
 internal ActiveDirectorySiteLinkBridge(DirectoryContext context, string bridgeName, ActiveDirectoryTransportType transport, bool existing)
 {
     this.links = new ActiveDirectorySiteLinkCollection();
     this.context = context;
     this.name = bridgeName;
     this.transport = transport;
     this.existing = existing;
 }
        public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
        {
            DirectoryEntry directoryEntry;

            this.systemDefaultInterval = new TimeSpan(0, 15, 0);
            this.sites = new ActiveDirectorySiteCollection();
            ValidateArgument(context, siteLinkName, transport);
            context        = new DirectoryContext(context);
            this.context   = context;
            this.name      = siteLinkName;
            this.transport = transport;
            try
            {
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string str = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
                string dn  = null;
                if (transport == ActiveDirectoryTransportType.Rpc)
                {
                    dn = "CN=IP,CN=Inter-Site Transports,CN=Sites," + str;
                }
                else
                {
                    dn = "CN=SMTP,CN=Inter-Site Transports,CN=Sites," + str;
                }
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
            }
            catch (COMException exception)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
            }
            try
            {
                string escapedPath = Utils.GetEscapedPath("cn=" + this.name);
                this.cachedEntry = directoryEntry.Children.Add(escapedPath, "siteLink");
                this.cachedEntry.Properties["cost"].Value         = 100;
                this.cachedEntry.Properties["replInterval"].Value = 180;
                if (schedule != null)
                {
                    this.cachedEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
                }
            }
            catch (COMException exception2)
            {
                if (((exception2.ErrorCode == -2147016656) && Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode)) && (transport == ActiveDirectoryTransportType.Smtp))
                {
                    throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
                }
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception2);
            }
            finally
            {
                directoryEntry.Dispose();
            }
        }
    public static System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
    {
      Contract.Requires(context != null);
      Contract.Requires(siteLinkName != null);

      Contract.Ensures(Contract.Result<ActiveDirectorySiteLink>() != null);

      return default(System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteLink);
    }
 public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
 {
     DirectoryEntry directoryEntry;
     this.systemDefaultInterval = new TimeSpan(0, 15, 0);
     this.sites = new ActiveDirectorySiteCollection();
     ValidateArgument(context, siteLinkName, transport);
     context = new DirectoryContext(context);
     this.context = context;
     this.name = siteLinkName;
     this.transport = transport;
     try
     {
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
         string str = (string) PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
         string dn = null;
         if (transport == ActiveDirectoryTransportType.Rpc)
         {
             dn = "CN=IP,CN=Inter-Site Transports,CN=Sites," + str;
         }
         else
         {
             dn = "CN=SMTP,CN=Inter-Site Transports,CN=Sites," + str;
         }
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
     }
     catch (COMException exception)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
     }
     catch (ActiveDirectoryObjectNotFoundException)
     {
         throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
     }
     try
     {
         string escapedPath = Utils.GetEscapedPath("cn=" + this.name);
         this.cachedEntry = directoryEntry.Children.Add(escapedPath, "siteLink");
         this.cachedEntry.Properties["cost"].Value = 100;
         this.cachedEntry.Properties["replInterval"].Value = 180;
         if (schedule != null)
         {
             this.cachedEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
         }
     }
     catch (COMException exception2)
     {
         if (((exception2.ErrorCode == -2147016656) && Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode)) && (transport == ActiveDirectoryTransportType.Smtp))
         {
             throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
         }
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception2);
     }
     finally
     {
         directoryEntry.Dispose();
     }
 }
 internal ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, bool existing, DirectoryEntry entry)
 {
     this.systemDefaultInterval = new TimeSpan(0, 15, 0);
     this.sites       = new ActiveDirectorySiteCollection();
     this.context     = context;
     this.name        = siteLinkName;
     this.transport   = transport;
     this.existing    = existing;
     this.cachedEntry = entry;
 }
Esempio n. 16
0
        internal ReplicationNeighbor(IntPtr addr, DirectoryServer server, Hashtable table)
        {
            DS_REPL_NEIGHBOR neighbor = new DS_REPL_NEIGHBOR();

            Marshal.PtrToStructure(addr, neighbor);

            _namingContext  = Marshal.PtrToStringUni(neighbor.pszNamingContext);
            _sourceServerDN = Marshal.PtrToStringUni(neighbor.pszSourceDsaDN);

            string transportDN = Marshal.PtrToStringUni(neighbor.pszAsyncIntersiteTransportDN);

            if (transportDN != null)
            {
                string rdn       = Utils.GetRdnFromDN(transportDN);
                string transport = (Utils.GetDNComponents(rdn))[0].Value;

                if (String.Compare(transport, "SMTP", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    _transportType = ActiveDirectoryTransportType.Smtp;
                }
                else
                {
                    _transportType = ActiveDirectoryTransportType.Rpc;
                }
            }

            _replicaFlags = (ReplicationNeighborOptions)neighbor.dwReplicaFlags;
            _uuidSourceDsaInvocationID = neighbor.uuidSourceDsaInvocationID;
            _usnLastObjChangeSynced    = neighbor.usnLastObjChangeSynced;
            _usnAttributeFilter        = neighbor.usnAttributeFilter;
            _timeLastSyncSuccess       = DateTime.FromFileTime(neighbor.ftimeLastSyncSuccess);
            _timeLastSyncAttempt       = DateTime.FromFileTime(neighbor.ftimeLastSyncAttempt);
            _lastSyncResult            = neighbor.dwLastSyncResult;
            _consecutiveSyncFailures   = neighbor.cNumConsecutiveSyncFailures;

            _server    = server;
            _nameTable = table;
        }
		public ActiveDirectorySiteLinkBridge (DirectoryContext context, string bridgeName, ActiveDirectoryTransportType transport)
		{

		}
Esempio n. 18
0
        public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
        {
            ValidateArgument(context, siteLinkName, transport);

            //  work with copy of the context
            context = new DirectoryContext(context);

            this.context = context;
            _name        = siteLinkName;
            _transport   = transport;

            // bind to the rootdse to get the configurationnamingcontext
            DirectoryEntry de;

            try
            {
                de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);

                string parentDN = null;
                if (transport == ActiveDirectoryTransportType.Rpc)
                {
                    parentDN = "CN=IP,CN=Inter-Site Transports,CN=Sites," + config;
                }
                else
                {
                    parentDN = "CN=SMTP,CN=Inter-Site Transports,CN=Sites," + config;
                }

                de = DirectoryEntryManager.GetDirectoryEntry(context, parentDN);
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                // this is the case where the context is a config set and we could not find an ADAM instance in that config set
                throw new ActiveDirectoryOperationException(String.Format(CultureInfo.CurrentCulture, SR.ADAMInstanceNotFoundInConfigSet, context.Name));
            }

            try
            {
                string rdn = "cn=" + _name;
                rdn         = Utils.GetEscapedPath(rdn);
                cachedEntry = de.Children.Add(rdn, "siteLink");
                cachedEntry.Properties["cost"].Value         = appDefaultCost;
                cachedEntry.Properties["replInterval"].Value = appDefaultInterval;
                if (schedule != null)
                {
                    cachedEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
                }
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked ((int)0x80072030))
                {
                    // if it is ADAM and transport type is SMTP, throw NotSupportedException.
                    DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                    if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                    {
                        throw new NotSupportedException(SR.NotSupportTransportSMTP);
                    }
                }

                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                de.Dispose();
            }
        }
Esempio n. 19
0
		private void GetPreferredBridgeheadServers(ActiveDirectoryTransportType transport)
		{
			string str;
			DirectoryServer domainController;
			string str1 = string.Concat("CN=Servers,", PropertyManager.GetPropertyValue(this.context, this.cachedEntry, PropertyManager.DistinguishedName));
			if (transport != ActiveDirectoryTransportType.Smtp)
			{
				str = string.Concat("CN=IP,CN=Inter-Site Transports,", this.siteDN);
			}
			else
			{
				str = string.Concat("CN=SMTP,CN=Inter-Site Transports,", this.siteDN);
			}
			DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(this.context, str1);
			string[] strArrays = new string[2];
			strArrays[0] = "dNSHostName";
			strArrays[1] = "distinguishedName";
			ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=server)(objectCategory=Server)(bridgeheadTransportList=", Utils.GetEscapedFilterValue(str), "))"), strArrays, SearchScope.OneLevel);
			SearchResultCollection searchResultCollections = null;
			try
			{
				searchResultCollections = aDSearcher.FindAll();
			}
			catch (COMException cOMException1)
			{
				COMException cOMException = cOMException1;
				throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException);
			}
			try
			{
				DirectoryEntry directoryEntry1 = null;
				foreach (SearchResult searchResult in searchResultCollections)
				{
					string searchResultPropertyValue = (string)PropertyManager.GetSearchResultPropertyValue(searchResult, PropertyManager.DnsHostName);
					DirectoryEntry directoryEntry2 = searchResult.GetDirectoryEntry();
					try
					{
						directoryEntry1 = directoryEntry2.Children.Find("CN=NTDS Settings", "nTDSDSA");
					}
					catch (COMException cOMException3)
					{
						COMException cOMException2 = cOMException3;
						throw ExceptionHelper.GetExceptionFromCOMException(this.context, cOMException2);
					}
					if (!this.IsADAM)
					{
						domainController = new DomainController(Utils.GetNewDirectoryContext(searchResultPropertyValue, DirectoryContextType.DirectoryServer, this.context), searchResultPropertyValue);
					}
					else
					{
						int propertyValue = (int)PropertyManager.GetPropertyValue(this.context, directoryEntry1, PropertyManager.MsDSPortLDAP);
						string str2 = searchResultPropertyValue;
						if (propertyValue != 0x185)
						{
							str2 = string.Concat(searchResultPropertyValue, ":", propertyValue);
						}
						domainController = new AdamInstance(Utils.GetNewDirectoryContext(str2, DirectoryContextType.DirectoryServer, this.context), str2);
					}
					if (transport != ActiveDirectoryTransportType.Smtp)
					{
						this.RPCBridgeheadServers.Add(domainController);
					}
					else
					{
						this.SMTPBridgeheadServers.Add(domainController);
					}
				}
			}
			finally
			{
				directoryEntry.Dispose();
				searchResultCollections.Dispose();
			}
		}
		public static ActiveDirectoryInterSiteTransport FindByTransportType(DirectoryContext context, ActiveDirectoryTransportType transport)
		{
			DirectoryEntry directoryEntry;
			if (context != null)
			{
				if (context.Name != null || context.isRootDomain())
				{
					if (context.Name == null || context.isRootDomain() || context.isServer() || context.isADAMConfigSet())
					{
						if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
						{
							throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
						}
						else
						{
							context = new DirectoryContext(context);
							try
							{
								directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
								string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
								string str = string.Concat("CN=Inter-Site Transports,CN=Sites,", propertyValue);
								if (transport != ActiveDirectoryTransportType.Rpc)
								{
									str = string.Concat("CN=SMTP,", str);
								}
								else
								{
									str = string.Concat("CN=IP,", str);
								}
								directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str);
							}
							catch (COMException cOMException1)
							{
								COMException cOMException = cOMException1;
								throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
							}
							catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException)
							{
								object[] name = new object[1];
								name[0] = context.Name;
								throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name));
							}
							try
							{
								string[] strArrays = new string[1];
								strArrays[0] = "options";
								directoryEntry.RefreshCache(strArrays);
							}
							catch (COMException cOMException3)
							{
								COMException cOMException2 = cOMException3;
								if (cOMException2.ErrorCode != -2147016656)
								{
									throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2);
								}
								else
								{
									DirectoryEntry directoryEntry1 = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
									if (!Utils.CheckCapability(directoryEntry1, Capability.ActiveDirectoryApplicationMode) || transport != ActiveDirectoryTransportType.Smtp)
									{
										object[] objArray = new object[1];
										objArray[0] = transport.ToString();
										throw new ActiveDirectoryObjectNotFoundException(Res.GetString("TransportNotFound", objArray), typeof(ActiveDirectoryInterSiteTransport), transport.ToString());
									}
									else
									{
										throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
									}
								}
							}
							return new ActiveDirectoryInterSiteTransport(context, transport, directoryEntry);
						}
					}
					else
					{
						throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
					}
				}
				else
				{
					throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
				}
			}
			else
			{
				throw new ArgumentNullException("context");
			}
		}
Esempio n. 21
0
        public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
        {
            ValidateArgument(context, siteLinkName, transport);

            //  work with copy of the context
            context = new DirectoryContext(context);

            // bind to the rootdse to get the configurationnamingcontext
            DirectoryEntry de;

            try
            {
                de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string config      = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);
                string containerDN = "CN=Inter-Site Transports,CN=Sites," + config;
                if (transport == ActiveDirectoryTransportType.Rpc)
                {
                    containerDN = "CN=IP," + containerDN;
                }
                else
                {
                    containerDN = "CN=SMTP," + containerDN;
                }
                de = DirectoryEntryManager.GetDirectoryEntry(context, containerDN);
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                // this is the case where the context is a config set and we could not find an ADAM instance in that config set
                throw new ActiveDirectoryOperationException(String.Format(CultureInfo.CurrentCulture, SR.ADAMInstanceNotFoundInConfigSet, context.Name));
            }

            try
            {
                ADSearcher adSearcher = new ADSearcher(de,
                                                       "(&(objectClass=siteLink)(objectCategory=SiteLink)(name=" + Utils.GetEscapedFilterValue(siteLinkName) + "))",
                                                       new string[] { "distinguishedName" },
                                                       SearchScope.OneLevel,
                                                       false, /* don't need paged search */
                                                       false  /* don't need to cache result */
                                                       );
                SearchResult srchResult = adSearcher.FindOne();
                if (srchResult == null)
                {
                    // no such sitelink object
                    Exception e = new ActiveDirectoryObjectNotFoundException(SR.DSNotFound, typeof(ActiveDirectorySiteLink), siteLinkName);
                    throw e;
                }
                else
                {
                    DirectoryEntry connectionEntry = srchResult.GetDirectoryEntry();
                    // it is an existing site object
                    ActiveDirectorySiteLink link = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, connectionEntry);
                    return(link);
                }
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked ((int)0x80072030))
                {
                    // if it is ADAM and transport type is SMTP, throw NotSupportedException.
                    DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                    if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                    {
                        throw new NotSupportedException(SR.NotSupportTransportSMTP);
                    }
                    else
                    {
                        // object is not found since we cannot even find the container in which to search
                        throw new ActiveDirectoryObjectNotFoundException(SR.DSNotFound, typeof(ActiveDirectorySiteLink), siteLinkName);
                    }
                }

                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                de.Dispose();
            }
        }
        public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
        {
            DirectoryEntry          directoryEntry;
            ActiveDirectorySiteLink link2;

            ValidateArgument(context, siteLinkName, transport);
            context = new DirectoryContext(context);
            try
            {
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string str = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
                string dn  = "CN=Inter-Site Transports,CN=Sites," + str;
                if (transport == ActiveDirectoryTransportType.Rpc)
                {
                    dn = "CN=IP," + dn;
                }
                else
                {
                    dn = "CN=SMTP," + dn;
                }
                directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
            }
            catch (COMException exception)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
            }
            try
            {
                SearchResult result = new ADSearcher(directoryEntry, "(&(objectClass=siteLink)(objectCategory=SiteLink)(name=" + Utils.GetEscapedFilterValue(siteLinkName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, false).FindOne();
                if (result == null)
                {
                    Exception exception2 = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName);
                    throw exception2;
                }
                DirectoryEntry entry = result.GetDirectoryEntry();
                link2 = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, entry);
            }
            catch (COMException exception3)
            {
                if (exception3.ErrorCode != -2147016656)
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(context, exception3);
                }
                if (Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode) && (transport == ActiveDirectoryTransportType.Smtp))
                {
                    throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
                }
                throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName);
            }
            finally
            {
                directoryEntry.Dispose();
            }
            return(link2);
        }
Esempio n. 23
0
        public static ActiveDirectoryInterSiteTransport FindByTransportType(DirectoryContext context, ActiveDirectoryTransportType transport)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // if target is not specified, then we determin the target from the logon credential, so if it is a local user context, it should fail
            if ((context.Name == null) && (!context.isRootDomain()))
            {
                throw new ArgumentException(Res.GetString(Res.ContextNotAssociatedWithDomain), "context");
            }

            // more validation for the context, if the target is not null, then it should be either forest name or server name
            if (context.Name != null)
            {
                if (!(context.isRootDomain() || context.isServer() || context.isADAMConfigSet()))
                {
                    throw new ArgumentException(Res.GetString(Res.NotADOrADAM), "context");
                }
            }

            if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
            {
                throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
            }

            //  work with copy of the context
            context = new DirectoryContext(context);

            // bind to the rootdse to get the configurationnamingcontext
            DirectoryEntry de;

            try
            {
                de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string config      = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);
                string containerDN = "CN=Inter-Site Transports,CN=Sites," + config;
                if (transport == ActiveDirectoryTransportType.Rpc)
                {
                    containerDN = "CN=IP," + containerDN;
                }
                else
                {
                    containerDN = "CN=SMTP," + containerDN;
                }
                de = DirectoryEntryManager.GetDirectoryEntry(context, containerDN);
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                // this is the case where the context is a config set and we could not find an ADAM instance in that config set
                throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name));
            }

            try
            {
                de.RefreshCache(new string[] { "options" });
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked ((int)0x80072030))
                {
                    // if it is ADAM and transport type is SMTP, throw NotSupportedException.
                    DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                    if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                    {
                        throw new NotSupportedException(Res.GetString(Res.NotSupportTransportSMTP));
                    }

                    throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.TransportNotFound, transport.ToString()), typeof(ActiveDirectoryInterSiteTransport), transport.ToString());
                }
                else
                {
                    throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                }
            }

            return(new ActiveDirectoryInterSiteTransport(context, transport, de));
        }
Esempio n. 24
0
 public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
 {
     throw new NotImplementedException();
 }
 public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
 {
 }
Esempio n. 26
0
        public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
        {
            ValidateArgument(context, siteLinkName, transport);

            //  work with copy of the context
            context = new DirectoryContext(context);

            this.context = context;
            _name = siteLinkName;
            _transport = transport;

            // bind to the rootdse to get the configurationnamingcontext
            DirectoryEntry de;

            try
            {
                de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);

                string parentDN = null;
                if (transport == ActiveDirectoryTransportType.Rpc)
                    parentDN = "CN=IP,CN=Inter-Site Transports,CN=Sites," + config;
                else
                    parentDN = "CN=SMTP,CN=Inter-Site Transports,CN=Sites," + config;

                de = DirectoryEntryManager.GetDirectoryEntry(context, parentDN);
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                // this is the case where the context is a config set and we could not find an ADAM instance in that config set
                throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name));
            }

            try
            {
                string rdn = "cn=" + _name;
                rdn = Utils.GetEscapedPath(rdn);
                cachedEntry = de.Children.Add(rdn, "siteLink");
                cachedEntry.Properties["cost"].Value = appDefaultCost;
                cachedEntry.Properties["replInterval"].Value = appDefaultInterval;
                if (schedule != null)
                    cachedEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked((int)0x80072030))
                {
                    // if it is ADAM and transport type is SMTP, throw NotSupportedException.
                    DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                    if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                    {
                        throw new NotSupportedException(Res.GetString(Res.NotSupportTransportSMTP));
                    }
                }

                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                de.Dispose();
            }
        }
Esempio n. 27
0
        private static void ValidateArgument(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
        {
            // basic validation first
            if (context == null)
                throw new ArgumentNullException("context");

            // if target is not specified, then we determin the target from the logon credential, so if it is a local user context, it should fail
            if ((context.Name == null) && (!context.isRootDomain()))
            {
                throw new ArgumentException(Res.GetString(Res.ContextNotAssociatedWithDomain), "context");
            }

            // more validation for the context, if the target is not null, then it should be either forest name or server name
            if (context.Name != null)
            {
                if (!(context.isRootDomain() || context.isServer() || context.isADAMConfigSet()))
                    throw new ArgumentException(Res.GetString(Res.NotADOrADAM), "context");
            }

            if (siteLinkName == null)
                throw new ArgumentNullException("siteLinkName");

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

            if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
                throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
        }
Esempio n. 28
0
        public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
        {
            ValidateArgument(context, siteLinkName, transport);

            //  work with copy of the context
            context = new DirectoryContext(context);

            // bind to the rootdse to get the configurationnamingcontext
            DirectoryEntry de;

            try
            {
                de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);
                string containerDN = "CN=Inter-Site Transports,CN=Sites," + config;
                if (transport == ActiveDirectoryTransportType.Rpc)
                    containerDN = "CN=IP," + containerDN;
                else
                    containerDN = "CN=SMTP," + containerDN;
                de = DirectoryEntryManager.GetDirectoryEntry(context, containerDN);
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                // this is the case where the context is a config set and we could not find an ADAM instance in that config set
                throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name));
            }

            try
            {
                ADSearcher adSearcher = new ADSearcher(de,
                                                      "(&(objectClass=siteLink)(objectCategory=SiteLink)(name=" + Utils.GetEscapedFilterValue(siteLinkName) + "))",
                                                      new string[] { "distinguishedName" },
                                                      SearchScope.OneLevel,
                                                      false, /* don't need paged search */
                                                      false /* don't need to cache result */
                                                      );
                SearchResult srchResult = adSearcher.FindOne();
                if (srchResult == null)
                {
                    // no such sitelink object
                    Exception e = new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySiteLink), siteLinkName);
                    throw e;
                }
                else
                {
                    DirectoryEntry connectionEntry = srchResult.GetDirectoryEntry();
                    // it is an existing site object
                    ActiveDirectorySiteLink link = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, connectionEntry);
                    return link;
                }
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked((int)0x80072030))
                {
                    // if it is ADAM and transport type is SMTP, throw NotSupportedException.
                    DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                    if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                    {
                        throw new NotSupportedException(Res.GetString(Res.NotSupportTransportSMTP));
                    }
                    else
                    {
                        // object is not found since we cannot even find the container in which to search
                        throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.DSNotFound), typeof(ActiveDirectorySiteLink), siteLinkName);
                    }
                }

                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                de.Dispose();
            }
        }
Esempio n. 29
0
 internal ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, bool existing, DirectoryEntry entry)
 {
     this.context = context;
     _name = siteLinkName;
     _transport = transport;
     this.existing = existing;
     this.cachedEntry = entry;
 }
Esempio n. 30
0
		public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
		{
			ReplicationConnection.ValidateArgument(context, name);
			if (sourceServer != null)
			{
				if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
				{
					throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
				}
				else
				{
					context = new DirectoryContext(context);
					this.ValidateTargetAndSourceServer(context, sourceServer);
					this.context = context;
					this.connectionName = name;
					this.transport = transport;
					DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
					try
					{
						try
						{
							string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ServerName);
							string str = string.Concat("CN=NTDS Settings,", propertyValue);
							directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str);
							string escapedPath = string.Concat("cn=", this.connectionName);
							escapedPath = Utils.GetEscapedPath(escapedPath);
							this.cachedDirectoryEntry = directoryEntry.Children.Add(escapedPath, "nTDSConnection");
							DirectoryContext directoryContext = sourceServer.Context;
							directoryEntry = DirectoryEntryManager.GetDirectoryEntry(directoryContext, WellKnownDN.RootDSE);
							string propertyValue1 = (string)PropertyManager.GetPropertyValue(directoryContext, directoryEntry, PropertyManager.ServerName);
							propertyValue1 = string.Concat("CN=NTDS Settings,", propertyValue1);
							this.cachedDirectoryEntry.Properties["fromServer"].Add(propertyValue1);
							if (schedule != null)
							{
								this.cachedDirectoryEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
							}
							string dNFromTransportType = Utils.GetDNFromTransportType(this.TransportType, context);
							directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dNFromTransportType);
							try
							{
								//TODO: REVIEW: URGENT!!: directoryEntry.Bind(true);
							}
							catch (COMException cOMException1)
							{
								COMException cOMException = cOMException1;
								if (cOMException.ErrorCode == -2147016656)
								{
									DirectoryEntry directoryEntry1 = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
									if (Utils.CheckCapability(directoryEntry1, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
									{
										throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
									}
								}
								throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
							}
							this.cachedDirectoryEntry.Properties["transportType"].Add(dNFromTransportType);
							this.cachedDirectoryEntry.Properties["enabledConnection"].Value = false;
							this.cachedDirectoryEntry.Properties["options"].Value = 0;
						}
						catch (COMException cOMException3)
						{
							COMException cOMException2 = cOMException3;
							throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2);
						}
					}
					finally
					{
						directoryEntry.Close();
					}
					return;
				}
			}
			else
			{
				throw new ArgumentNullException("sourceServer");
			}
		}
Esempio n. 31
0
		public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectoryTransportType transport) : this(context, name, sourceServer, null, transport)
		{
		}
Esempio n. 32
0
 public ActiveDirectorySiteLinkBridge(DirectoryContext context, string bridgeName, ActiveDirectoryTransportType transport)
 {
 }
 private static void ValidateArgument(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if ((context.Name == null) && !context.isRootDomain())
     {
         throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
     }
     if (((context.Name != null) && !context.isRootDomain()) && (!context.isServer() && !context.isADAMConfigSet()))
     {
         throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
     }
     if (siteLinkName == null)
     {
         throw new ArgumentNullException("siteLinkName");
     }
     if (siteLinkName.Length == 0)
     {
         throw new ArgumentException(Res.GetString("EmptyStringParameter"), "siteLinkName");
     }
     if ((transport < ActiveDirectoryTransportType.Rpc) || (transport > ActiveDirectoryTransportType.Smtp))
     {
         throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
     }
 }
Esempio n. 34
0
 // Methods
 public static ActiveDirectoryInterSiteTransport FindByTransportType(DirectoryContext context, ActiveDirectoryTransportType transport)
 {
 }
Esempio n. 35
0
 internal ActiveDirectoryInterSiteTransport(DirectoryContext context, ActiveDirectoryTransportType transport, DirectoryEntry entry)
 {
     _context     = context;
     _transport   = transport;
     _cachedEntry = entry;
 }
        public void FindByTransportType_InvalidTransport_ThrowsInvalidEnumArgumentException(ActiveDirectoryTransportType transport)
        {
            var context = new DirectoryContext(DirectoryContextType.ConfigurationSet, "Name");

            AssertExtensions.Throws <InvalidEnumArgumentException>("value", () => ActiveDirectoryInterSiteTransport.FindByTransportType(context, transport));
        }
		internal ActiveDirectoryInterSiteTransport(DirectoryContext context, ActiveDirectoryTransportType transport, DirectoryEntry entry)
		{
			this.siteLinkCollection = new ReadOnlySiteLinkCollection();
			this.bridgeCollection = new ReadOnlySiteLinkBridgeCollection();
			this.context = context;
			this.transport = transport;
			this.cachedEntry = entry;
		}
 private static void ValidateArgument(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
 {
     if (context == null)
     {
         throw new ArgumentNullException("context");
     }
     if ((context.Name == null) && !context.isRootDomain())
     {
         throw new ArgumentException(Res.GetString("ContextNotAssociatedWithDomain"), "context");
     }
     if (((context.Name != null) && !context.isRootDomain()) && (!context.isServer() && !context.isADAMConfigSet()))
     {
         throw new ArgumentException(Res.GetString("NotADOrADAM"), "context");
     }
     if (siteLinkName == null)
     {
         throw new ArgumentNullException("siteLinkName");
     }
     if (siteLinkName.Length == 0)
     {
         throw new ArgumentException(Res.GetString("EmptyStringParameter"), "siteLinkName");
     }
     if ((transport < ActiveDirectoryTransportType.Rpc) || (transport > ActiveDirectoryTransportType.Smtp))
     {
         throw new InvalidEnumArgumentException("value", (int) transport, typeof(ActiveDirectoryTransportType));
     }
 }
Esempio n. 39
0
 public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
 {
     ReplicationConnection.ValidateArgument(context, name);
     if (sourceServer != null)
     {
         if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
         {
             throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
         }
         else
         {
             context = new DirectoryContext(context);
             this.ValidateTargetAndSourceServer(context, sourceServer);
             this.context        = context;
             this.connectionName = name;
             this.transport      = transport;
             DirectoryEntry directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
             try
             {
                 try
                 {
                     string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ServerName);
                     string str           = string.Concat("CN=NTDS Settings,", propertyValue);
                     directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str);
                     string escapedPath = string.Concat("cn=", this.connectionName);
                     escapedPath = Utils.GetEscapedPath(escapedPath);
                     this.cachedDirectoryEntry = directoryEntry.Children.Add(escapedPath, "nTDSConnection");
                     DirectoryContext directoryContext = sourceServer.Context;
                     directoryEntry = DirectoryEntryManager.GetDirectoryEntry(directoryContext, WellKnownDN.RootDSE);
                     string propertyValue1 = (string)PropertyManager.GetPropertyValue(directoryContext, directoryEntry, PropertyManager.ServerName);
                     propertyValue1 = string.Concat("CN=NTDS Settings,", propertyValue1);
                     this.cachedDirectoryEntry.Properties["fromServer"].Add(propertyValue1);
                     if (schedule != null)
                     {
                         this.cachedDirectoryEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
                     }
                     string dNFromTransportType = Utils.GetDNFromTransportType(this.TransportType, context);
                     directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dNFromTransportType);
                     try
                     {
                         //TODO: REVIEW: URGENT!!: directoryEntry.Bind(true);
                     }
                     catch (COMException cOMException1)
                     {
                         COMException cOMException = cOMException1;
                         if (cOMException.ErrorCode == -2147016656)
                         {
                             DirectoryEntry directoryEntry1 = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                             if (Utils.CheckCapability(directoryEntry1, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                             {
                                 throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
                             }
                         }
                         throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
                     }
                     this.cachedDirectoryEntry.Properties["transportType"].Add(dNFromTransportType);
                     this.cachedDirectoryEntry.Properties["enabledConnection"].Value = false;
                     this.cachedDirectoryEntry.Properties["options"].Value           = 0;
                 }
                 catch (COMException cOMException3)
                 {
                     COMException cOMException2 = cOMException3;
                     throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2);
                 }
             }
             finally
             {
                 directoryEntry.Close();
             }
             return;
         }
     }
     else
     {
         throw new ArgumentNullException("sourceServer");
     }
 }
        internal ActiveDirectorySiteLinkBridge(DirectoryContext context, string bridgeName, ActiveDirectoryTransportType transport, bool existing)
        {
            this.context = context;
            _name = bridgeName;
            _transport = transport;

            _existing = existing;
        }
Esempio n. 41
0
 public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport) : this(context, siteLinkName, transport, null)
 {
 }
Esempio n. 42
0
 public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
 {
     throw new NotImplementedException();
 }
Esempio n. 43
0
        private static void ValidateArgument(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
        {
            // basic validation first
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            // if target is not specified, then we determin the target from the logon credential, so if it is a local user context, it should fail
            if ((context.Name == null) && (!context.isRootDomain()))
            {
                throw new ArgumentException(SR.ContextNotAssociatedWithDomain, "context");
            }

            // more validation for the context, if the target is not null, then it should be either forest name or server name
            if (context.Name != null)
            {
                if (!(context.isRootDomain() || context.isServer() || context.isADAMConfigSet()))
                {
                    throw new ArgumentException(SR.NotADOrADAM, "context");
                }
            }

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

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

            if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
            {
                throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
            }
        }
 public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, ActiveDirectorySchedule schedule)
 {
   Contract.Requires(context != null);
   Contract.Requires(siteLinkName != null);
   // Schedule can be null
 }
        public static ActiveDirectoryInterSiteTransport FindByTransportType(DirectoryContext context, ActiveDirectoryTransportType transport)
        {
            Contract.Requires(context != null);

            Contract.Ensures(Contract.Result <ActiveDirectoryInterSiteTransport>() != null);

            return(default(ActiveDirectoryInterSiteTransport));
        }
 public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
 {
   Contract.Requires(context != null);
   Contract.Requires(siteLinkName != null);
 }
		public static ActiveDirectorySiteLinkBridge FindByName (DirectoryContext context, string bridgeName, ActiveDirectoryTransportType transport)
		{
			throw new NotImplementedException ();
		}
Esempio n. 48
0
 public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
 {
 }
 public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectoryTransportType transport)
 {
     Contract.Requires(context != null);
     Contract.Requires(!string.IsNullOrEmpty(name));
 }
 public ActiveDirectorySiteLinkBridge(DirectoryContext context, string bridgeName, ActiveDirectoryTransportType transport)
 {
     Contract.Requires(context != null);
     Contract.Requires(bridgeName != null);
 }
Esempio n. 51
0
		internal ReplicationNeighbor(IntPtr addr, DirectoryServer server, Hashtable table)
		{
			DS_REPL_NEIGHBOR dSREPLNEIGHBOR = new DS_REPL_NEIGHBOR();
			Marshal.PtrToStructure(addr, dSREPLNEIGHBOR);
			this.namingContext = Marshal.PtrToStringUni(dSREPLNEIGHBOR.pszNamingContext);
			this.sourceServerDN = Marshal.PtrToStringUni(dSREPLNEIGHBOR.pszSourceDsaDN);
			string stringUni = Marshal.PtrToStringUni(dSREPLNEIGHBOR.pszAsyncIntersiteTransportDN);
			if (stringUni != null)
			{
				string rdnFromDN = Utils.GetRdnFromDN(stringUni);
				string value = Utils.GetDNComponents(rdnFromDN)[0].Value;
				if (string.Compare(value, "SMTP", StringComparison.OrdinalIgnoreCase) != 0)
				{
					this.transportType = ActiveDirectoryTransportType.Rpc;
				}
				else
				{
					this.transportType = ActiveDirectoryTransportType.Smtp;
				}
			}
			this.replicaFlags = (ReplicationNeighbor.ReplicationNeighborOptions)((long)dSREPLNEIGHBOR.dwReplicaFlags);
			this.uuidSourceDsaInvocationID = dSREPLNEIGHBOR.uuidSourceDsaInvocationID;
			this.usnLastObjChangeSynced = dSREPLNEIGHBOR.usnLastObjChangeSynced;
			this.usnAttributeFilter = dSREPLNEIGHBOR.usnAttributeFilter;
			this.timeLastSyncSuccess = DateTime.FromFileTime(dSREPLNEIGHBOR.ftimeLastSyncSuccess);
			this.timeLastSyncAttempt = DateTime.FromFileTime(dSREPLNEIGHBOR.ftimeLastSyncAttempt);
			this.lastSyncResult = dSREPLNEIGHBOR.dwLastSyncResult;
			this.consecutiveSyncFailures = dSREPLNEIGHBOR.cNumConsecutiveSyncFailures;
			this.server = server;
			this.nameTable = table;
		}
        public static System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteLinkBridge FindByName(DirectoryContext context, string bridgeName, ActiveDirectoryTransportType transport)
        {
            Contract.Requires(context != null);
            Contract.Requires(bridgeName != null);

            Contract.Ensures(Contract.Result <ActiveDirectorySiteLink>() != null);

            return(default(System.DirectoryServices.ActiveDirectory.ActiveDirectorySiteLinkBridge));
        }
Esempio n. 53
0
		public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
		{
			DirectoryEntry directoryEntry;
			ActiveDirectorySiteLink activeDirectorySiteLink;
			ActiveDirectorySiteLink.ValidateArgument(context, siteLinkName, transport);
			context = new DirectoryContext(context);
			try
			{
				directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
				string propertyValue = (string)PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
				string str = string.Concat("CN=Inter-Site Transports,CN=Sites,", propertyValue);
				if (transport != ActiveDirectoryTransportType.Rpc)
				{
					str = string.Concat("CN=SMTP,", str);
				}
				else
				{
					str = string.Concat("CN=IP,", str);
				}
				directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, str);
			}
			catch (COMException cOMException1)
			{
				COMException cOMException = cOMException1;
				throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException);
			}
			catch (ActiveDirectoryObjectNotFoundException activeDirectoryObjectNotFoundException)
			{
				object[] name = new object[1];
				name[0] = context.Name;
				throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", name));
			}
			try
			{
				try
				{
					string[] strArrays = new string[1];
					strArrays[0] = "distinguishedName";
					ADSearcher aDSearcher = new ADSearcher(directoryEntry, string.Concat("(&(objectClass=siteLink)(objectCategory=SiteLink)(name=", Utils.GetEscapedFilterValue(siteLinkName), "))"), strArrays, SearchScope.OneLevel, false, false);
					SearchResult searchResult = aDSearcher.FindOne();
					if (searchResult != null)
					{
						DirectoryEntry directoryEntry1 = searchResult.GetDirectoryEntry();
						ActiveDirectorySiteLink activeDirectorySiteLink1 = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, directoryEntry1);
						activeDirectorySiteLink = activeDirectorySiteLink1;
					}
					else
					{
						Exception exception = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName);
						throw exception;
					}
				}
				catch (COMException cOMException3)
				{
					COMException cOMException2 = cOMException3;
					if (cOMException2.ErrorCode != -2147016656)
					{
						throw ExceptionHelper.GetExceptionFromCOMException(context, cOMException2);
					}
					else
					{
						DirectoryEntry directoryEntry2 = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
						if (!Utils.CheckCapability(directoryEntry2, Capability.ActiveDirectoryApplicationMode) || transport != ActiveDirectoryTransportType.Smtp)
						{
							throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName);
						}
						else
						{
							throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
						}
					}
				}
			}
			finally
			{
				directoryEntry.Dispose();
			}
			return activeDirectorySiteLink;
		}
Esempio n. 54
0
 public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectoryTransportType transport) : this(context, name, sourceServer, null, transport)
 {
 }
 public static ActiveDirectorySiteLink FindByName(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport)
 {
     DirectoryEntry directoryEntry;
     ActiveDirectorySiteLink link2;
     ValidateArgument(context, siteLinkName, transport);
     context = new DirectoryContext(context);
     try
     {
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
         string str = (string) PropertyManager.GetPropertyValue(context, directoryEntry, PropertyManager.ConfigurationNamingContext);
         string dn = "CN=Inter-Site Transports,CN=Sites," + str;
         if (transport == ActiveDirectoryTransportType.Rpc)
         {
             dn = "CN=IP," + dn;
         }
         else
         {
             dn = "CN=SMTP," + dn;
         }
         directoryEntry = DirectoryEntryManager.GetDirectoryEntry(context, dn);
     }
     catch (COMException exception)
     {
         throw ExceptionHelper.GetExceptionFromCOMException(context, exception);
     }
     catch (ActiveDirectoryObjectNotFoundException)
     {
         throw new ActiveDirectoryOperationException(Res.GetString("ADAMInstanceNotFoundInConfigSet", new object[] { context.Name }));
     }
     try
     {
         SearchResult result = new ADSearcher(directoryEntry, "(&(objectClass=siteLink)(objectCategory=SiteLink)(name=" + Utils.GetEscapedFilterValue(siteLinkName) + "))", new string[] { "distinguishedName" }, SearchScope.OneLevel, false, false).FindOne();
         if (result == null)
         {
             Exception exception2 = new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName);
             throw exception2;
         }
         DirectoryEntry entry = result.GetDirectoryEntry();
         link2 = new ActiveDirectorySiteLink(context, siteLinkName, transport, true, entry);
     }
     catch (COMException exception3)
     {
         if (exception3.ErrorCode != -2147016656)
         {
             throw ExceptionHelper.GetExceptionFromCOMException(context, exception3);
         }
         if (Utils.CheckCapability(DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE), Capability.ActiveDirectoryApplicationMode) && (transport == ActiveDirectoryTransportType.Smtp))
         {
             throw new NotSupportedException(Res.GetString("NotSupportTransportSMTP"));
         }
         throw new ActiveDirectoryObjectNotFoundException(Res.GetString("DSNotFound"), typeof(ActiveDirectorySiteLink), siteLinkName);
     }
     finally
     {
         directoryEntry.Dispose();
     }
     return link2;
 }
Esempio n. 56
0
        public ReplicationConnection(DirectoryContext context, string name, DirectoryServer sourceServer, ActiveDirectorySchedule schedule, ActiveDirectoryTransportType transport)
        {
            ValidateArgument(context, name);

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

            if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
            {
                throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));
            }

            //  work with copy of the context
            context = new DirectoryContext(context);

            ValidateTargetAndSourceServer(context, sourceServer);

            this.context    = context;
            _connectionName = name;
            _transport      = transport;

            DirectoryEntry de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);

            try
            {
                string serverDN            = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ServerName);
                string connectionContainer = "CN=NTDS Settings," + serverDN;
                de = DirectoryEntryManager.GetDirectoryEntry(context, connectionContainer);

                // create the connection entry
                string rdn = "cn=" + _connectionName;
                rdn = Utils.GetEscapedPath(rdn);
                cachedDirectoryEntry = de.Children.Add(rdn, "nTDSConnection");

                // set all the properties

                // sourceserver property
                DirectoryContext sourceServerContext = sourceServer.Context;
                de = DirectoryEntryManager.GetDirectoryEntry(sourceServerContext, WellKnownDN.RootDSE);
                string serverName = (string)PropertyManager.GetPropertyValue(sourceServerContext, de, PropertyManager.ServerName);
                serverName = "CN=NTDS Settings," + serverName;

                cachedDirectoryEntry.Properties["fromServer"].Add(serverName);

                // schedule property
                if (schedule != null)
                {
                    cachedDirectoryEntry.Properties["schedule"].Value = schedule.GetUnmanagedSchedule();
                }

                // transporttype property
                string transportPath = Utils.GetDNFromTransportType(TransportType, context);
                // verify that the transport is supported
                de = DirectoryEntryManager.GetDirectoryEntry(context, transportPath);
                try
                {
                    de.Bind(true);
                }
                catch (COMException e)
                {
                    if (e.ErrorCode == unchecked ((int)0x80072030))
                    {
                        // if it is ADAM and transport type is SMTP, throw NotSupportedException.
                        DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                        if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                        {
                            throw new NotSupportedException(SR.NotSupportTransportSMTP);
                        }
                    }

                    throw ExceptionHelper.GetExceptionFromCOMException(context, e);
                }

                cachedDirectoryEntry.Properties["transportType"].Add(transportPath);

                // enabledConnection property
                cachedDirectoryEntry.Properties["enabledConnection"].Value = false;

                // options
                cachedDirectoryEntry.Properties["options"].Value = 0;
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            finally
            {
                de.Close();
            }
        }
 public ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport) : this(context, siteLinkName, transport, null)
 {
 }
 internal ActiveDirectoryInterSiteTransport(DirectoryContext context, ActiveDirectoryTransportType transport, DirectoryEntry entry)
 {
     _context = context;
     _transport = transport;
     _cachedEntry = entry;
 }
 internal ActiveDirectorySiteLink(DirectoryContext context, string siteLinkName, ActiveDirectoryTransportType transport, bool existing, DirectoryEntry entry)
 {
     this.systemDefaultInterval = new TimeSpan(0, 15, 0);
     this.sites = new ActiveDirectorySiteCollection();
     this.context = context;
     this.name = siteLinkName;
     this.transport = transport;
     this.existing = existing;
     this.cachedEntry = entry;
 }
        public static ActiveDirectoryInterSiteTransport FindByTransportType(DirectoryContext context, ActiveDirectoryTransportType transport)
        {
            if (context == null)
                throw new ArgumentNullException("context");

            // if target is not specified, then we determin the target from the logon credential, so if it is a local user context, it should fail
            if ((context.Name == null) && (!context.isRootDomain()))
            {
                throw new ArgumentException(Res.GetString(Res.ContextNotAssociatedWithDomain), "context");
            }

            // more validation for the context, if the target is not null, then it should be either forest name or server name
            if (context.Name != null)
            {
                if (!(context.isRootDomain() || context.isServer() || context.isADAMConfigSet()))
                    throw new ArgumentException(Res.GetString(Res.NotADOrADAM), "context");
            }

            if (transport < ActiveDirectoryTransportType.Rpc || transport > ActiveDirectoryTransportType.Smtp)
                throw new InvalidEnumArgumentException("value", (int)transport, typeof(ActiveDirectoryTransportType));

            //  work with copy of the context
            context = new DirectoryContext(context);

            // bind to the rootdse to get the configurationnamingcontext
            DirectoryEntry de;

            try
            {
                de = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                string config = (string)PropertyManager.GetPropertyValue(context, de, PropertyManager.ConfigurationNamingContext);
                string containerDN = "CN=Inter-Site Transports,CN=Sites," + config;
                if (transport == ActiveDirectoryTransportType.Rpc)
                    containerDN = "CN=IP," + containerDN;
                else
                    containerDN = "CN=SMTP," + containerDN;
                de = DirectoryEntryManager.GetDirectoryEntry(context, containerDN);
            }
            catch (COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }
            catch (ActiveDirectoryObjectNotFoundException)
            {
                // this is the case where the context is a config set and we could not find an ADAM instance in that config set
                throw new ActiveDirectoryOperationException(Res.GetString(Res.ADAMInstanceNotFoundInConfigSet, context.Name));
            }

            try
            {
                de.RefreshCache(new string[] { "options" });
            }
            catch (COMException e)
            {
                if (e.ErrorCode == unchecked((int)0x80072030))
                {
                    // if it is ADAM and transport type is SMTP, throw NotSupportedException.
                    DirectoryEntry tmpDE = DirectoryEntryManager.GetDirectoryEntry(context, WellKnownDN.RootDSE);
                    if (Utils.CheckCapability(tmpDE, Capability.ActiveDirectoryApplicationMode) && transport == ActiveDirectoryTransportType.Smtp)
                    {
                        throw new NotSupportedException(Res.GetString(Res.NotSupportTransportSMTP));
                    }

                    throw new ActiveDirectoryObjectNotFoundException(Res.GetString(Res.TransportNotFound, transport.ToString()), typeof(ActiveDirectoryInterSiteTransport), transport.ToString());
                }
                else
                    throw ExceptionHelper.GetExceptionFromCOMException(context, e);
            }

            return new ActiveDirectoryInterSiteTransport(context, transport, de);
        }