Пример #1
0
        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());
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <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:";
            }
        }
Пример #4
0
        private void InitBlock()
        {
            _conn = new LdapConnection();
            LdapUrl lUrl = new LdapUrl(SearchRoot.ADsPath);

            _Host = lUrl.Host;
            _Port = lUrl.Port;
            _conn.Connect(_Host, _Port);
            _conn.Bind(SearchRoot.Username, SearchRoot.Password, (Novell.Directory.Ldap.AuthenticationTypes)SearchRoot.AuthenticationType);
        }
Пример #5
0
        /// <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);
        }
Пример #6
0
        public void Ctor_StartsWithURL()
        {
            var url = new LdapUrl("url:ldap://foo.example.com/");

            Assert.Equal(389, url.Port);
            Assert.Equal("foo.example.com", url.Host);
            Assert.False(url.Secure);
            Assert.Null(url.AttributeArray);
            Assert.Null(url.Extensions);
            Assert.Null(url.Filter);
            Assert.Equal(LdapConnection.ScopeBase, url.Scope);
        }
Пример #7
0
        public void Ctor_LdapS()
        {
            var url = new LdapUrl("ldaps://foo.example.com/");

            Assert.Equal(636, url.Port);
            Assert.Equal("foo.example.com", url.Host);
            Assert.True(url.Secure);
            Assert.Null(url.AttributeArray);
            Assert.Null(url.Extensions);
            Assert.Null(url.Filter);
            Assert.Equal(LdapConnection.ScopeBase, url.Scope);
        }
Пример #8
0
        public void Ctor_EnclosedWithBrackets()
        {
            var url = new LdapUrl("<ldap://foo.example.com/>");

            Assert.Equal(389, url.Port);
            Assert.Equal("foo.example.com", url.Host);
            Assert.False(url.Secure);
            Assert.Null(url.AttributeArray);
            Assert.Null(url.Extensions);
            Assert.Null(url.Filter);
            Assert.Equal(LdapConnection.ScopeBase, url.Scope);
        }
Пример #9
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);
        }
Пример #10
0
        internal static string GetLdapUrlString(string host, int port, string dn)
        {
            LdapUrl lUrl;

            if (port == LdapConnection.DEFAULT_PORT)
            {
                lUrl = new LdapUrl(host, 0, dn);
            }
            else
            {
                lUrl = new LdapUrl(host, port, dn);
            }
            return(lUrl.ToString());
        }
Пример #11
0
        public void Ctor_WithDn()
        {
            var urlStr = "ldap://foo.example.com/cn=admin,ou=marketing,o=corporation";
            var url    = new LdapUrl(urlStr);

            Assert.Equal(389, url.Port);
            Assert.Equal("foo.example.com", url.Host);
            Assert.False(url.Secure);
            Assert.Null(url.AttributeArray);
            Assert.Null(url.Extensions);
            Assert.Null(url.Filter);
            Assert.Equal(LdapConnection.ScopeBase, url.Scope);
            Assert.Equal("cn=admin,ou=marketing,o=corporation", url.GetDn());
        }
        /// <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);
        }
Пример #13
0
        public void Ctor_Complex()
        {
            var urlStr = "ldap://foo.example.com/cn=admin,ou=marketing,o=corporation?attr1,attr2,attr3?sub?(objectclass=*)?ext1,ext2,ext3";
            var url    = new LdapUrl(urlStr);

            Assert.Equal(389, url.Port);
            Assert.Equal("foo.example.com", url.Host);
            Assert.False(url.Secure);
            Assert.Equal("cn=admin,ou=marketing,o=corporation", url.GetDn());
            Assert.Equal(LdapConnection.ScopeSub, url.Scope);
            Assert.Equal("(objectclass=*)", url.Filter);
            Assert.Equal(new[] { "attr1", "attr2", "attr3" }, url.AttributeArray);
            Assert.Equal(new[] { "ext1", "ext2", "ext3" }, url.Extensions);
        }
Пример #14
0
 /// <summary> Initializes the Connection and other properties.
 ///
 /// </summary>
 private void InitBlock()
 {
     try                     {
         LdapUrl lUrl = new LdapUrl(_Bpath);
         _Conn = new LdapConnection();
         _Conn.Connect(lUrl.Host, lUrl.Port);
         _Conn.Bind(_Buser, _Bpass);
     }
     catch (LdapException ex)                 {
         throw ex;
     }
     catch (Exception e)                              {
         throw e;
     }
 }
Пример #15
0
 /// <summary> Initializes the Connection and other properties.
 ///
 /// </summary>
 private void InitBlock()
 {
     try                     {
         _conn = new LdapConnection();
         LdapUrl lUrl = new LdapUrl(ADsPath);
         _conn.Connect(lUrl.Host, lUrl.Port);
         _conn.Bind(Username, Password, (Novell.Directory.Ldap.AuthenticationTypes)AuthenticationType);
     }
     catch (LdapException ex)                 {
         throw ex;
     }
     catch (Exception e)                      {
         throw e;
     }
 }
Пример #16
0
        /// <summary>
        /// Searches the directory store at the specified path to see whether
        /// an entry exists
        /// </summary>
        /// <param name="path">
        /// The path at which to search the directory store.
        /// </param>
        /// <returns>
        /// true if an entry exists in the directory store at the specified
        /// path; otherwise, false.
        /// </returns>
        public static bool Exists(string path)
        {
            LdapConnection aconn = new LdapConnection();
            LdapUrl        lurl  = new LdapUrl(path);

            aconn.Connect(lurl.Host, lurl.Port);
            aconn.Bind("", "");
            if (CheckEntry(aconn, path))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private static LdapConnection LdapConnection(
            string loginId, string password, ParameterAccessor.Parts.Ldap ldap)
        {
            var url = new LdapUrl(ldap.LdapSearchRoot);
            var con = new LdapConnection();

            con.Connect(url.Host, url.Port);
            if (loginId != null && password != null)
            {
                con.Bind(loginId, password);
            }
            else
            {
                con.Bind(null, null);
            }
            return(con);
        }
Пример #18
0
        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";
        }
Пример #19
0
// private DirectoryEntry conn;

        /// <summary>
        ///     Construct the ReferralInfo class.
        /// </summary>
        /// <param name="lc">
        ///     The DirectoryEntry opened to process this referral.
        /// </param>
        /// <param name="refUrl">
        ///     The URL string associated with this connection.
        /// </param>
        public ReferralInfo(LdapConnection lc, string[] refList, LdapUrl refUrl)
        {
            ReferralConnection = lc;
            ReferralUrl        = refUrl;
            ReferralList       = refList;
        }