getDN() public method

Returns the base distinguished name encapsulated in the URL.
public getDN ( ) : System.String
return System.String
		/// <summary>
		/// Initializes the Entry specific properties e.g entry DN etc.
		/// </summary>
		void InitEntry()
		{			
			LdapUrl lUrl = new LdapUrl (ADsPath);
			string dn = lUrl.getDN();
			if (dn != null ) {
				if (String.Compare (dn,"rootDSE",true) == 0)
					InitToRootDse (lUrl.Host,lUrl.Port);
				else {
				DN userDn = new DN (dn);
				String[] lRdn = userDn.explodeDN(false);
				_Name = (string)lRdn[0];
				_Parent = new DirectoryEntry(conn);
				_Parent.Path = GetLdapUrlString (lUrl.Host,lUrl.Port,userDn.Parent.ToString ());
				}
			}
			else			{
				_Name=lUrl.Host+":"+lUrl.Port;
				_Parent = new DirectoryEntry(conn);
				_Parent.Path = "Ldap:";
			}
		}
Example #2
0
		/// <summary> Builds a new request replacing dn, scope, and filter where approprate
		/// 
		/// </summary>
		/// <param name="msg">the original LdapMessage to build the new request from
		/// 
		/// </param>
		/// <param name="url">the referral url
		/// 
		/// </param>
		/// <returns> a new LdapMessage with appropriate information replaced
		/// 
		/// </returns>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		private LdapMessage rebuildRequest(LdapMessage msg, LdapUrl url, bool reference)
		{
			
			System.String dn = url.getDN(); // new base
			System.String filter = null;
			
			switch (msg.Type)
			{
				
				case LdapMessage.SEARCH_REQUEST: 
					if (reference)
					{
						filter = url.Filter;
					}
					break;
					// We are allowed to get a referral for the following
				
				case LdapMessage.ADD_REQUEST: 
				case LdapMessage.BIND_REQUEST: 
				case LdapMessage.COMPARE_REQUEST: 
				case LdapMessage.DEL_REQUEST: 
				case LdapMessage.EXTENDED_REQUEST: 
				case LdapMessage.MODIFY_RDN_REQUEST: 
				case LdapMessage.MODIFY_REQUEST: 
					break;
					// The following return no response
				
				case LdapMessage.ABANDON_REQUEST: 
				case LdapMessage.UNBIND_REQUEST: 
				default: 
					throw new LdapLocalException(ExceptionMessages.IMPROPER_REFERRAL, new System.Object[]{msg.Type}, LdapException.LOCAL_ERROR);
			}
			
			return msg.Clone(dn, filter, reference);
		}
Example #3
0
		/// <summary> Synchronously reads the entry specified by the Ldap URL, using the
		/// specified constraints.
		/// 
		/// When this method is called, a new connection is created
		/// automatically, using the host and port specified in the URL. After
		/// finding the entry, the method closes the connection (in other words,
		/// it disconnects from the Ldap server).
		/// 
		/// If the URL specifies a filter and scope, they are not used. Of the
		/// information specified in the URL, this method only uses the Ldap host
		/// name and port number, the base distinguished name (DN), and the list
		/// of attributes to return.
		/// 
		/// </summary>
		/// <returns> The entry specified by the base DN.
		/// 
		/// </returns>
		/// <param name="toGet">      Ldap URL specifying the entry to read.
		/// 
		/// </param>
		/// <param name="cons">      Constraints specific to the operation.
		/// 
		/// </param>
		/// <exception> LdapException if the object was not found
		/// </exception>
		public static LdapEntry Read(LdapUrl toGet, LdapSearchConstraints cons)
		{
			LdapConnection lconn = new LdapConnection();
			lconn.Connect(toGet.Host, toGet.Port);
			LdapEntry toReturn = lconn.Read(toGet.getDN(), toGet.AttributeArray, cons);
			lconn.Disconnect();
			return toReturn;
		}
		/// <summary>
		/// Checks whether the entry exists in the Ldap directory or not
		/// </summary>
		/// <param name="lconn">
		/// Connection used to communicate with directory
		/// </param>
		/// <param name="epath">
		/// path of the entry
		/// </param>
		/// <returns>
		///		true of the entry exists in the Ldap directory
		///		false if entry doesn't exists
		/// </returns>
		private static bool CheckEntry(LdapConnection lconn, string epath)
		{
			LdapUrl lUrl=new LdapUrl(epath);
			string eDn=lUrl.getDN();
			if(eDn==null)
			{
				eDn = String.Empty;
			}
			// rootDSE is a "virtual" entry that always exists
			else if (String.Compare (eDn,"rootDSE",true) == 0)
				return true;

			string[] attrs={"objectClass"};
			try
			{
				LdapSearchResults lsc=lconn.Search(	eDn,
					LdapConnection.SCOPE_BASE,
					"objectClass=*",
					attrs,
					false);
				while(lsc.hasMore())
				{
					LdapEntry nextEntry = null;
					try 
					{
						nextEntry = lsc.next();
					}
					catch(LdapException e) 
					{
						// Exception is thrown, go for next entry
						throw e;
					}
					break;
				}

			}
			catch(LdapException le)
			{
				if(le.ResultCode == LdapException.NO_SUCH_OBJECT)
				{
					return false;
				}
				else
				{
					throw le;
				}
			}
			catch(Exception e)
			{
				throw e;
			}
			return true;
		}
		/// <summary>
		/// Initializes the Entry specific properties e.g entry DN etc.
		/// </summary>
		void InitEntry()
		{
			LdapUrl lUrl=new LdapUrl (Path);
			if(lUrl.getDN()!=null)			{
				DN userDn = new DN(lUrl.getDN());
				String[] lRdn = userDn.explodeDN(false);
				_Name = (string)lRdn[0];
				_Parent = new DirectoryEntry(conn);
				LdapUrl cUrl=new LdapUrl(lUrl.Host,lUrl.Port,userDn.Parent.ToString());
				_Parent.Path=cUrl.ToString();
			}
			else			{
				_Name=lUrl.Host+":"+lUrl.Port;
				_Parent = new DirectoryEntry(conn);
				_Parent.Path = "Ldap:";
			}
		}
		/// <summary>
		/// Deletes a child DirectoryEntry from this collection
		/// </summary>
		/// <param name="entry">The DirectoryEntry to delete</param>
		public void Remove(	DirectoryEntry entry )
		{
			LdapUrl Burl=new LdapUrl(_Bpath);
			string eFDN = entry.Name + "," + Burl.getDN();
			Conn.Delete( eFDN);
		}
		/// <summary> Creates a request to create a new entry in the container.
		/// 
		/// </summary>
		/// <param name="name"> RDN of the entry to be created
		/// </param>
		/// <param name="schemaClassName"> StructuralClassName of the entry to be
		/// created.
		/// </param>
		public DirectoryEntry Add(	string name,string schemaClassName)
		{
			DirectoryEntry ent=new DirectoryEntry(Conn);
			LdapUrl Burl=new LdapUrl(_Bpath);
			string eFdn=name+","+Burl.getDN();
			LdapUrl curl=new LdapUrl(Burl.Host,Burl.Port,eFdn);
			ent.Path=curl.ToString();
			ent.Nflag = true;
			return ent;
		}
Example #8
0
		/// <summary> Creates a request to create a new entry in the container.
		/// 
		/// </summary>
		/// <param name="name"> RDN of the entry to be created
		/// </param>
		/// <param name="schemaClassName"> StructuralClassName of the entry to be
		/// created.
		/// </param>
		public DirectoryEntry Add(	string name,string schemaClassName)
		{
			DirectoryEntry ent=new DirectoryEntry(Conn);
			LdapUrl Burl=new LdapUrl(_Bpath);
			string baseDn = Burl.getDN();
			string eFdn=((baseDn != null && baseDn.Length != 0) ? (name + "," + baseDn) : name);
			LdapUrl curl=new LdapUrl(Burl.Host,Burl.Port,eFdn);
			ent.Path=curl.ToString();
			ent.Nflag = true;
			return ent;
		}
Example #9
-1
		/*
		* Ldap URL search
		*/
		
		/// <summary> Synchronously perfoms the search specified by the Ldap URL, using
		/// the specified search constraints (such as the maximum number of
		/// entries to find or the maximum time to wait for search results).
		/// 
		/// When this method is called, a new connection is created
		/// automatically, using the host and port specified in the URL. After
		/// all search results have been received from the server, the method
		/// closes the connection (in other words, it disconnects from the Ldap
		/// server).
		/// 
		/// As part of the search constraints, a choice can be made as to whether
		/// to have the results delivered all at once or in smaller batches. If
		/// the results are to be delivered in smaller batches, each iteration
		/// blocks only until the next batch of results is returned.
		/// 
		/// 
		/// </summary>
		/// <param name="toGet">         Ldap URL specifying the entry to read.
		/// 
		/// </param>
		/// <param name="cons">          The constraints specific to the search.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		public static LdapSearchResults Search(LdapUrl toGet, LdapSearchConstraints cons)
		{
			LdapConnection lconn = new LdapConnection();
			lconn.Connect(toGet.Host, toGet.Port);
			if (cons == null)
			{
				// This is a clone, so we already have our own copy
				cons = lconn.SearchConstraints;
			}
			else
			{
				// get our own copy of user's constraints because we modify it
				cons = (LdapSearchConstraints) cons.Clone();
			}
			cons.BatchSize = 0; // Must wait until all results arrive
			LdapSearchResults toReturn = lconn.Search(toGet.getDN(), toGet.Scope, toGet.Filter, toGet.AttributeArray, false, cons);
			lconn.Disconnect();
			return toReturn;
		}