Beispiel #1
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);
            }
        }
        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);
            }
        }
Beispiel #3
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);
            }
        }
        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);
            }
        }