private void InitToRootDse(string host,int port) { if ( host == null ) host = DefaultHost; if ( port < 0 ) port = DefaultPort; LdapUrl rootPath = new LdapUrl (host,port,String.Empty); string [] attrs = new string [] {"+","*"}; DirectoryEntry rootEntry = new DirectoryEntry (rootPath.ToString (),this.Username,this.Password,this.AuthenticationType); DirectorySearcher searcher = new DirectorySearcher (rootEntry,null,attrs,SearchScope.Base); SearchResult result = searcher.FindOne (); // copy properties from search result PropertyCollection pcoll = new PropertyCollection (); foreach (string propertyName in result.Properties.PropertyNames) { System.Collections.IEnumerator enumerator = result.Properties [propertyName].GetEnumerator (); if (enumerator != null) while (enumerator.MoveNext ()) if (String.Compare (propertyName,"ADsPath",true) != 0) pcoll [propertyName].Add (enumerator.Current); } this.SetProperties (pcoll); this._Name = "rootDSE"; }
/// <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> /// Checks whether the entry with the specified Relative distinguised name /// exists or not. /// </summary> /// <param name="rdn"> Relative distinguished name of the entry</param> /// <returns>DirectoryEntry object of Entry if entry exists, /// Null if entry doesn't exist </returns> private DirectoryEntry CheckEntry(string rdn) { string Ofdn=null; DirectoryEntry cEntry=null; Ofdn=rdn+","+Basedn; string[] attrs={"objectClass"}; try { LdapSearchResults lsc= Conn.Search( Ofdn, LdapConnection.SCOPE_BASE, "objectClass=*", attrs, false); while(lsc.hasMore()) { LdapEntry nextEntry = null; try { nextEntry = lsc.next(); cEntry = new DirectoryEntry(Conn); LdapUrl Burl=new LdapUrl(_Bpath); LdapUrl curl=new LdapUrl(Burl.Host,Burl.Port,Ofdn); cEntry.Path=curl.ToString(); } catch(LdapException e) { // Exception is thrown, go for next entry throw e; } break; } } catch(LdapException le) { if(le.ResultCode == LdapException.NO_SUCH_OBJECT) { return null; } else { throw le; } } catch(Exception e) { throw e; } return cEntry; }
/// <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; }
public IEnumerator GetEnumerator() { m_oValues= new ArrayList(); string[] attrs={"objectClass"}; LdapSearchResults lsc= Conn.Search( Basedn, LdapConnection.SCOPE_ONE, "objectClass=*", attrs, false); LdapUrl Burl=new LdapUrl(_Bpath); string host=Burl.Host; int port=Burl.Port; while (lsc.hasMore()) { LdapEntry nextEntry = null; try { nextEntry = lsc.next(); } catch(LdapException e) { // Exception is thrown, go for next entry continue; } DirectoryEntry dEntry=new DirectoryEntry(Conn); string eFdn=nextEntry.DN; LdapUrl curl=new LdapUrl(host,port,eFdn); dEntry.Path=curl.ToString(); m_oValues.Add((DirectoryEntry) dEntry); } return m_oValues.GetEnumerator(); }
/// <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; }