Ejemplo n.º 1
0
        public int Ldap_Count_Entries()
        {
            //return (LdapAPI.ldap_count_entries(_ldapHandle.Handle, _ldapMessage));
            Logger.Log(string.Format(
                           "Calling Ldap_Count_Entries"),
                       Logger.ldapTracingLevel);
            int ret = -1;

            try
            {
                Logger.Log(string.Format(
                               "Calling ldap_count_entries(_ldapHandle{0},_ldapMessage{1})",
                               _ldapHandle, _ldapMessage), Logger.ldapTracingLevel);

                if (_ldapHandle != null && _ldapHandle.Handle != IntPtr.Zero)
                {
                    ret = LdapAPI.ldap_count_entries(_ldapHandle.Handle, _ldapMessage);

                    if (ret == 0)
                    {
                        Logger.Log(string.Format(
                                       "Calling ldap_count_entries :ret={0})", ret), Logger.ldapTracingLevel);
                    }
                }
                return(ret);
            }
            catch (Exception ex)
            {
                Logger.LogException("LdapMessage.Ldap_Count_Entries", ex);
                return(ret);
            }
        }
Ejemplo n.º 2
0
        public List <LdapEntry> Ldap_Get_Entries()
        {
            List <LdapEntry> entries = new List <LdapEntry>();

            Logger.Log(string.Format("Calling Ldap_Get_Entries()"), Logger.ldapTracingLevel);
            try
            {
                Logger.Log(string.Format(
                               "Calling ldap_first_entry(_ldapHandle{0},_ldapMessage{1}",
                               _ldapHandle, _ldapMessage), Logger.ldapTracingLevel);

                if (_ldapHandle != null && _ldapHandle.Handle != IntPtr.Zero)
                {
                    IntPtr currentEntry = LdapAPI.ldap_first_entry(_ldapHandle.Handle, _ldapMessage);

                    Logger.Log(String.Format(
                                   "Result of ldap_first_entry():{0}",
                                   currentEntry), Logger.ldapTracingLevel);

                    if (currentEntry == IntPtr.Zero)
                    {
                        return(entries);
                    }
                    do
                    {
                        entries.Add(new LdapEntry(this, currentEntry));

                        Logger.Log(string.Format(
                                       "Calling ldap_next_entry(_ldapHandle{0},_ldapMessage{1}",
                                       _ldapHandle, _ldapMessage),
                                   Logger.ldapTracingLevel);

                        currentEntry = LdapAPI.ldap_next_entry(_ldapHandle.Handle, currentEntry);

                        Logger.Log(String.Format(
                                       "Result of ldap_next_entry():{0}",
                                       currentEntry), Logger.ldapTracingLevel);
                    } while (currentEntry != IntPtr.Zero);
                }

                return(entries);
            }
            catch (Exception ex)
            {
                Logger.LogException("LdapMessage.Ldap_Get_Entries", ex);
                return(null);
            }
        }
Ejemplo n.º 3
0
 public void FreeMessage()
 {
     Logger.Log(string.Format("Calling FreeMessage()"), Logger.ldapTracingLevel);
     try
     {
         Logger.Log(String.Format("FreeMessage :{0}"), Logger.ldapTracingLevel);
         int ret = LdapAPI.ldap_msgfree(_ldapMessage);
         if (ret != 0)
         {
             Logger.Log(ErrorCodes.LDAPString(ret), Logger.ldapTracingLevel);
         }
     }
     catch (Exception ex)
     {
         Logger.LogException("LdapMessage.FreeMessage", ex);
     }
 }
Ejemplo n.º 4
0
        public string[] GetAttributeNames(IntPtr ldapEntry)
        {
            List <string> attrs = new List <string>();

            IntPtr pBerval = new IntPtr(0);

            Monitor.Enter(Ldap_ApiCallSync);
            try
            {
                unsafe
                {
                    if (_ldapHandle != null && _ldapHandle.Handle != IntPtr.Zero)
                    {
                        IntPtr ppBerval = Marshal.AllocHGlobal(IntPtr.Size);

                        Marshal.StructureToPtr(pBerval, ppBerval, false);

                        Logger.Log(string.Format(
                                       "In GetAttributeNames calling ldap_first_attribute(_ldapHandle{0},ldapEntry{1},ppBerval {2})",
                                       _ldapHandle, ldapEntry, ppBerval), Logger.ldapTracingLevel);

                        string strTmp = LdapAPI.ldap_first_attribute(_ldapHandle.Handle, ldapEntry, ppBerval);

                        Logger.Log(string.Format("Result of ldap_first_attribute(strTmp)", strTmp), Logger.ldapTracingLevel);

                        string attrName = new string(strTmp.ToCharArray());

                        if (!IntPtr.Zero.Equals(ppBerval))
                        {
                            pBerval = Marshal.ReadIntPtr(ppBerval);

                            if (!IntPtr.Zero.Equals(pBerval))
                            {
                                while (!string.IsNullOrEmpty(attrName))
                                {
                                    Logger.Log(string.Format(
                                                   "In GetAttributeNames calling ldap_next_attribute(_ldapHandle{0},ldapEntry{1},berValStarStar{2})",
                                                   _ldapHandle, ldapEntry, ppBerval), Logger.ldapTracingLevel);

                                    strTmp = LdapAPI.ldap_next_attribute(_ldapHandle.Handle, ldapEntry, pBerval);

                                    Logger.Log(string.Format("Result of ldap_next_attribute(strTmp)", strTmp), Logger.ldapTracingLevel);

                                    if (string.IsNullOrEmpty(strTmp))
                                    {
                                        attrName = null;
                                    }
                                    else
                                    {
                                        attrName = new string(strTmp.ToCharArray());
                                        attrs.Add(attrName);
                                    }
                                }
                                LdapAPI.ber_free(pBerval, 0);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("LdapMessage.GetAttributeNames", ex);
            }
            finally
            {
                Monitor.Exit(Ldap_ApiCallSync);
            }
            return(attrs.ToArray());
        }
Ejemplo n.º 5
0
 public string GetDN(IntPtr ldapEntry)
 {
     return(LdapAPI.ldap_get_dn(_ldapHandle.Handle, ldapEntry));
 }
Ejemplo n.º 6
0
        public LdapValue[] GetNonBervals(IntPtr ldapEntry, string attrName)
        {
            Logger.Log(string.Format("Calling GetNonBervals(ldapEntry{0},attrName{1})",
                                     ldapEntry, attrName), Logger.ldapTracingLevel);

            Monitor.Enter(Ldap_ApiCallSync);
            try
            {
                unsafe
                {
                    if (_ldapHandle != null && _ldapHandle.Handle != IntPtr.Zero)
                    {
                        IntPtr ppValues = LdapAPI.ldap_get_values(_ldapHandle.Handle, ldapEntry, attrName);

                        if (IntPtr.Zero.Equals(ppValues))
                        {
                            Logger.Log(String.Format(
                                           "GetNonBervals({0}): values = null", attrName),
                                       Logger.ldapLogLevel);
                            return(null);
                        }

                        int valueCount = LdapAPI.ldap_count_values(ppValues);

                        if (valueCount == 0)
                        {
                            Logger.Log(String.Format(
                                           "GetNonBervals({0}): values.Count == 0", attrName),
                                       Logger.ldapLogLevel);
                            return(null);
                        }
                        string[]    resultStr  = new string[valueCount];
                        LdapValue[] ldapValues = new LdapValue[valueCount];

                        for (int i = 0; i < valueCount; i++)
                        {
                            IntPtr pValue = Marshal.ReadIntPtr(ppValues, i * IntPtr.Size);
                            if (IntPtr.Zero.Equals(pValue))
                            {
                                resultStr[i] = null;
                            }
                            else
                            {
                                string tmpString = Marshal.PtrToStringAnsi(pValue);

                                if (String.IsNullOrEmpty(tmpString))
                                {
                                    resultStr[i] = null;
                                }
                                else
                                {
                                    resultStr[i] = new string(tmpString.ToCharArray());
                                }
                            }
                            ldapValues[i] = new LdapValue(ADSType.ADSTYPE_DN_STRING, resultStr[i]);
                        }
                        return(ldapValues);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("LdapMessage.GetNonBervals", ex);
                return(null);
            }
            finally
            {
                Monitor.Exit(Ldap_ApiCallSync);
            }
        }
Ejemplo n.º 7
0
        public LdapValue[] GetBervals(IntPtr ldapEntry, string attrName)
        {
            Logger.Log(string.Format("Calling GetBervals(ldapEntry{0},attrName{1})", ldapEntry, attrName), Logger.ldapTracingLevel);
            Monitor.Enter(Ldap_ApiCallSync);
            try
            {
                unsafe
                {
                    if (_ldapHandle != null && _ldapHandle.Handle != IntPtr.Zero)
                    {
                        IntPtr ppBervals = LdapAPI.ldap_get_values_len(_ldapHandle.Handle, ldapEntry, attrName);

                        if (IntPtr.Zero.Equals(ppBervals))
                        {
                            return(null);
                        }

                        int berCount =
                            LdapAPI.ldap_count_values_len(LdapAPI.ldap_get_values_len(_ldapHandle.Handle, ldapEntry, attrName));
                        Logger.Log(String.Format("Result of ldap_get_values_len(berCount)", berCount), Logger.ldapTracingLevel);

                        if (berCount == 0)
                        {
                            return(null);
                        }

                        LdapValue[] ldapValues = new LdapValue[berCount];
                        for (int i = 0; i < berCount; i++)
                        {
                            IntPtr pBerval = Marshal.ReadIntPtr(ppBervals, i * IntPtr.Size);
                            if (IntPtr.Zero.Equals(pBerval))
                            {
                                ldapValues[i] = null;
                            }
                            else
                            {
                                Berval tmpBer = (Berval)Marshal.PtrToStructure(pBerval, typeof(Berval));

                                if (tmpBer.bv_len == 0)
                                {
                                    ldapValues[i] = null;
                                }
                                else
                                {
                                    byte[] tmpBytes = new byte[tmpBer.bv_len];

                                    for (int j = 0; j < (int)tmpBer.bv_len; j++)
                                    {
                                        tmpBytes[j] = Marshal.ReadByte(tmpBer.bv_val, j);
                                    }
                                    ldapValues[i] = new LdapValue(ADSType.ADSTYPE_DN_STRING, tmpBytes);

                                    ldapValues[i].stringData = BitConverter.ToString(tmpBytes);
                                }
                            }
                        }
                        return(ldapValues);
                    }
                    else
                    {
                        return(null);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.LogException("LdapMessage.GetAttributeNames", ex);
                return(null);
            }
            finally
            {
                Monitor.Exit(Ldap_ApiCallSync);
            }
        }