Example #1
0
        public void LdapSimpleBindS(string dn, string passwd)
        {
            SetVersion(LDAPOption.LDAP_VERSION);
            var returnError = LdapClientLibrary.ldap_simple_bind_s(this._connection, dn, passwd);

            ErrorCheckerHelper.Validate(returnError);
        }
Example #2
0
        public void ModifyObject(string basedn, LdapMod[] attrs)
        {
            IntPtr basednPtr = IntPtr.Zero;

            basednPtr = Marshal.StringToHGlobalAnsi(basedn);

            IntPtr[] umattrs = new IntPtr[attrs.Length + 1];
            for (int i = 0; i < attrs.Length; i++)
            {
                umattrs[i] = attrs[i].convertToUnmanaged();
            }

            umattrs[attrs.Length] = IntPtr.Zero; /* NULL Termination */

            var returnError = LdapClientLibrary.ldap_modify_ext_s(this._connection, basednPtr, umattrs, null, null);

            for (int i = 0; i < attrs.Length; i++)
            {
                attrs[i].Free();
                Marshal.FreeHGlobal(umattrs[i]);
            }

            Marshal.FreeHGlobal(basednPtr);

            ErrorCheckerHelper.Validate((int)returnError);
        }
Example #3
0
 public void FreeMessage()
 {
     if ((this._message != IntPtr.Zero))
     {
         LdapClientLibrary.ldap_msgfree(this._message);
     }
 }
Example #4
0
        public void VmDirSafeLDAPBind(string host, string upn, string passwd)
        {
            SetVersion(LDAPOption.LDAP_VERSION);
            var VmDirError  = LdapClientLibrary.VmDirSafeLDAPBind(out this._connection, host, upn, passwd);
            var returnError = LdapError.VmDirMapLdapError((int)VmDirError);

            ErrorCheckerHelper.Validate(returnError);
        }
Example #5
0
 public static string ErrorCodeToString(int error)
 {
     if (error != (int)LdapStatus.LDAP_SUCCESS)
     {
         var errorPointer = LdapClientLibrary.ldap_err2string(error);
         var errorString  = Marshal.PtrToStringAnsi(errorPointer);
         return(errorString);
     }
     return(error.ToString());
 }
Example #6
0
 public static void Validate(int error)
 {
     if (error != (int)LdapStatus.LDAP_SUCCESS)
     {
         var errorPointer = LdapClientLibrary.ldap_err2string(error);
         var errorString  = Marshal.PtrToStringAnsi(errorPointer);
         var message      = string.Format("{0}-{1} (error code = {2})", "Exception thrown from LDAP", errorString, error);
         var exception    = new LdapException(message);
         exception.LdapError = (LdapStatus)Enum.Parse(typeof(LdapStatus), error.ToString(), false);
         throw exception;
     }
 }
Example #7
0
        public void LdapParsePageControl(IntPtr serverControls, ref IntPtr cookie)
        {
            ulong totalCount = 0;

            var returnError = LdapClientLibrary.ldap_parse_page_control(
                _connection,
                serverControls,
                out totalCount,
                ref cookie);

            ErrorCheckerHelper.Validate((int)returnError);
        }
Example #8
0
        //Override
        public int GetEntriesCount()
        {
            int returnError;

            try
            {
                returnError = LdapClientLibrary.ldap_count_entries(this._connection.GetIntPtr(), this._message);
                return(returnError);
            }
            catch (Exception exception)
            {
                throw exception;
            }
        }
Example #9
0
        public ILdapMessage LdapSearchExtS(string querybase, int scope, string filter, string[] attrs, int attrsonly, IntPtr timeout, int sizelimit)
        {
            ILdapMessage message;

            if (attrs != null)
            {
                Array.Resize(ref attrs, attrs.Length + 1);/* NULL Termination */
            }
            var returnError = LdapClientLibrary.ldap_search_ext_s(this._connection, querybase, scope, filter, attrs, 0, 0, 0, timeout, sizelimit, ref this._result);

            ErrorCheckerHelper.Validate(returnError);
            message = new LdapMessage(this, _result);
            return(message);
        }
Example #10
0
        public IntPtr LdapCreatePageControl(int pageSize, IntPtr cookie, bool isCritical)
        {
            IntPtr pageControl = IntPtr.Zero;

            var returnError = LdapClientLibrary.ldap_create_page_control(
                _connection,
                pageSize,
                cookie,
                isCritical ? 1 : 0,
                out pageControl);

            ErrorCheckerHelper.Validate((int)returnError);

            return(pageControl);
        }
Example #11
0
        //Override
        public string getDN()
        {
            IntPtr dnPointer = IntPtr.Zero;
            string dn;

            try
            {
                dnPointer = LdapClientLibrary.ldap_get_dn(this._message.GetConnection().GetIntPtr(), this._entry);
                dn        = Marshal.PtrToStringAnsi(dnPointer);
                return(dn);
            }
            finally
            {
                LdapClientLibrary.ldap_memfree(dnPointer);
            }
        }
Example #12
0
        public void LdapParseResult(ILdapMessage msg, ref IntPtr serverControls, bool fFreeIt)
        {
            int errorCode = 0;

            var returnError = LdapClientLibrary.ldap_parse_result(
                _connection,
                _result,
                out errorCode,
                null,
                null,
                null,
                ref serverControls,
                fFreeIt ? 1 : 0);

            ErrorCheckerHelper.Validate((int)returnError);
        }
Example #13
0
        //Override
        public List <string> getAttributeNames()
        {
            IntPtr        attributePointer = IntPtr.Zero, berPointer = IntPtr.Zero;
            List <string> attributeList = new List <string>();

            try
            {
                attributePointer = LdapClientLibrary.ldap_first_attribute(this._message.GetConnection().GetIntPtr(), this._entry, out berPointer);
                while (attributePointer != IntPtr.Zero)
                {
                    var attributeName = Marshal.PtrToStringAnsi(attributePointer);
                    attributeList.Add(attributeName);
                    LdapClientLibrary.ldap_memfree(attributePointer);
                    attributePointer = LdapClientLibrary.ldap_next_attribute(this._message.GetConnection().GetIntPtr(), this._entry, berPointer);
                }
                return(attributeList);
            }
            finally
            {
                LdapClientLibrary.ldap_value_free(attributePointer);
                LdapClientLibrary.ber_free(berPointer, 0);
            }
        }
Example #14
0
        public List <ILdapEntry> GetEntries()
        {
            int numberEntries           = LdapClientLibrary.ldap_count_entries(this._connection.GetIntPtr(), this._message);
            List <ILdapEntry> entryList = new List <ILdapEntry>(numberEntries);

            if (numberEntries > 0)
            {
                try
                {
                    IntPtr pEntry = LdapClientLibrary.ldap_first_entry(this._connection.GetIntPtr(), this._message);
                    while ((pEntry != null) && (pEntry != IntPtr.Zero))
                    {
                        entryList.Add(new LdapEntry(this, pEntry));
                        pEntry = LdapClientLibrary.ldap_next_entry(this._connection.GetIntPtr(), pEntry);
                    }
                }
                catch (Exception exception)
                {
                    throw exception;
                }
            }
            return(entryList);
        }
Example #15
0
        //Override
        public List <LdapValue> getAttributeValues(string attributeName)
        {
            List <LdapValue> attributeValues  = new List <LdapValue>();
            IntPtr           attributePointer = IntPtr.Zero;
            int i = 0;

            try
            {
                attributePointer = LdapClientLibrary.ldap_get_values(this._message.GetConnection().GetIntPtr(), this._entry, attributeName);
                var count = LdapClientLibrary.ldap_count_values(attributePointer);
                while (i < count)
                {
                    var attributeValuePointer = Marshal.ReadIntPtr(attributePointer, System.Runtime.InteropServices.Marshal.SizeOf(attributePointer) * i);
                    var attributeValue        = new LdapValue(Marshal.PtrToStringAnsi(attributeValuePointer));
                    attributeValues.Add(attributeValue);
                    i++;
                }
                return(attributeValues);
            }
            finally
            {
                LdapClientLibrary.ldap_value_free(attributePointer);
            }
        }
Example #16
0
        public void DeleteObject(string dn)
        {
            var returnError = LdapClientLibrary.ldap_delete_ext_s(this._connection, dn, null, null);

            ErrorCheckerHelper.Validate((int)returnError);
        }
Example #17
0
        public void SetOption(int option, IntPtr ptrVersion)
        {
            var returnError = LdapClientLibrary.ldap_set_option(this._connection, (int)option, ptrVersion);

            ErrorCheckerHelper.Validate(returnError);
        }
Example #18
0
        public static ILdapConnection LdapInit(string HostName, int PortNumber)
        {
            var ldapPointer = LdapClientLibrary.ldap_init(HostName, PortNumber);

            return(new LdapConnection(ldapPointer));
        }
Example #19
0
        public void LdapUnbindS()
        {
            var returnError = LdapClientLibrary.ldap_unbind_s(this._connection);

            ErrorCheckerHelper.Validate(returnError);
        }
Example #20
0
 public void CleanSearch()
 {
     LdapClientLibrary.ldap_msgfree(this._result);
 }