示例#1
0
        public bool ExistDn(string dn)
        {
            SearchRequest request;

            try
            {
                Connect2();
                DnObj dnObj = DnObj.Parse(dn);
                request = new SearchRequest(dnObj.BaseDn, dnObj.Filter, SearchScope.Subtree);
                SearchResponse result = (SearchResponse)ldapConnexion.SendRequest(request);
                return((result != null) && result.Entries.Count > 0);
            }
            catch (LdapException ex)
            {
                Console.WriteLine(String.Format("Error LdapException FindPeDateMajCert {0}...", ex.Message));
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
            catch (DirectoryOperationException ex)
            {
                Console.WriteLine(String.Format("Error DirectoryOperationException FindPeDateMajCert {0}...", ex.Message));
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
            catch (Exception ex)
            {
                Console.WriteLine(String.Format("Error Exception FindPeDateMajCert {0}...", ex.Message));
                Console.WriteLine(ex.StackTrace);
                throw ex;
            }
        }
示例#2
0
        public static DnObj Parse(string dn)
        {
            DnObj dnObj = new DnObj();


            int idx = dn.IndexOf(',');

            dnObj.BaseDn = dn.Substring(idx + 1);
            //if(dnObj.BaseDn=="Comptes")
            //{

            //    dnObj.BaseDn = dn;
            //    dnObj.Filter = "(ObjectClass = *)";
            //}
            //else
            //{
            dnObj.Filter = $"({dn.Substring(0, idx)})";
            int idx2 = dnObj.Filter.IndexOf('=');

            dnObj.Name     = dnObj.Filter.Substring(idx2 + 1);
            dnObj.Name     = dnObj.Name.Substring(0, dnObj.Name.Length - 1);
            dnObj.TypeName = dnObj.Filter.Substring(1, idx2 - 1);
            //}

            return(dnObj);
        }
示例#3
0
        public LdapObj ReadDn(String dn, String[] attribs = null)
        {
            DnObj          dnObj      = DnObj.Parse(dn);
            List <LdapObj> lstLdapObj = SearchDn(dnObj.BaseDn, dnObj.Filter, SearchScope.OneLevel, attribs);

            if ((lstLdapObj != null) && lstLdapObj.Count > 0)
            {
                return(lstLdapObj[0]);
            }

            return(null);
        }
示例#4
0
 public List <LdapAttribut> GetAttributs(String dn, String[] attributs)
 {
     try
     {
         DnObj          dnObj  = DnObj.Parse(dn);
         List <LdapObj> lstObj = SearchDn(dnObj.BaseDn, dnObj.Filter, SearchScope.OneLevel, attributs);
         if (lstObj.Count > 0)
         {
             return(lstObj[0].ldapAttributs.Select(e => e.Value).ToList());
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         throw ex;
     }
     return(null);
 }