예제 #1
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);
        }
예제 #2
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:";
            }
        }
예제 #3
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);
        }
예제 #4
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);
        }