public int Ldap_Search_Ext( IntPtr ld, string basedn, int scope, string filter, string[] attrs, int attrsonly, LDAPControl[] ServerControls, LDAPControl[] ClientControls, int TimeLimit, int SizeLimit, out LdapMessage ldapMessage ) { int ret = -1; ldapMessage = null; IntPtr umldapMessage = new IntPtr(); LdapTimeVal tm = new LdapTimeVal(5, 6); Monitor.Enter(Ldap_ApiCallSync); try { Logger.Log(String.Format("Calling Ldap_Search_Ext(basedn={0}, scope={1}, filter={2})", basedn, scope, filter), Logger.ldapLogLevel); unsafe { ret = Ldap_Rebind_S(); if (ret != 0) { Logger.Log(ErrorCodes.LDAPString(ret), Logger.ldapLogLevel); ldapMessage = null; return ret; } ret = LdapAPI.ldap_search_s(_ld, basedn, scope, filter, attrs, attrsonly, out umldapMessage); if (ret != 0) { Logger.Log(ErrorCodes.LDAPString(ret), Logger.ldapLogLevel); ldapMessage = null; return ret; } if (umldapMessage == IntPtr.Zero) { ldapMessage = null; return ret; } ldapMessage = new LdapMessage(this, umldapMessage); return ret; } } catch (Exception ex) { Logger.LogException("LdapHandle.Ldap_Search_Ext", ex); return ret; } finally { Monitor.Exit(Ldap_ApiCallSync); } }
public int Ldap_Add_Ext_S( string dn, LDAPMod[] attrs, LDAPControl[] ServerControls, LDAPControl[] ClientControls, out LdapMessage ldapMessage ) { int ret = -1; ldapMessage = null; Monitor.Enter(Ldap_ApiCallSync); try { IntPtr umldapMessage = new IntPtr(); IntPtr[] umattrs = new IntPtr[attrs.Length + 1]; for (int i = 0; i < attrs.Length; i++) { umattrs[i] = attrs[i].ConvertToUM(); } umattrs[attrs.Length] = IntPtr.Zero; IntPtr[] umServerControls = new IntPtr[ServerControls.Length]; for (int i = 0; i < ServerControls.Length; i++) { umServerControls[i] = ServerControls[i].ConvertToUM(); } IntPtr[] umClientControls = new IntPtr[ClientControls.Length]; for (int i = 0; i < ClientControls.Length; i++) { umClientControls[i] = ClientControls[i].ConvertToUM(); } Logger.Log(string.Format("Calling Ldap_Add_Ext_S(_ld={0}, dn={1}, umattrs={2})", _ld, dn, umattrs), Logger.ldapLogLevel); ret = Ldap_Rebind_S(); if (ret != 0) { Logger.Log(ErrorCodes.LDAPString(ret), Logger.ldapLogLevel); return ret; } unsafe { ret = LdapAPI.ldap_add_ext_s(_ld, dn, umattrs, umServerControls, umClientControls, out umldapMessage); } Logger.Log(String.Format("LdapHandle.Ldap_Add_Ext_S: ret={0}", ret), Logger.ldapLogLevel); if (ret != 0) { Logger.Log(ErrorCodes.LDAPString(ret), Logger.ldapLogLevel); } ldapMessage = new LdapMessage(this, umldapMessage); for (int i = 0; i < attrs.Length; i++) { attrs[i].ldapfree(); } return ret; } catch (Exception ex) { Logger.LogException("LdapHandle.Ldap_Add_Ext_S", ex); return ret; } finally { Monitor.Exit(Ldap_ApiCallSync); } }
public int setserver_pageControloption() { //set server control LDAP_OPT_SERVER_CONTROLS Berval berVal = new Berval(0, IntPtr.Zero); LDAPControl c = new LDAPControl(berVal, LdapMessage.LDAP_CONTROL_PAGEDRESULTS, 'F'); IntPtr[] ctrls = new IntPtr[2]; ctrls[0] = c.ConvertToUM(); ctrls[1] = IntPtr.Zero; IntPtr arrayCtrls = IntPtr.Zero; // Allocate memory to store the array of pointers int sizeOfIntPtr = Marshal.SizeOf(typeof(IntPtr)); arrayCtrls = Marshal.AllocCoTaskMem(sizeOfIntPtr * ctrls.Length); // Stuff the pointers into the array for (int counter = 0; counter < ctrls.Length; counter++) Marshal.WriteIntPtr(arrayCtrls, counter * sizeOfIntPtr, ctrls[counter]); int ret = Ldap_Set_Option(LDAP_OPT_SERVER_CONTROLS, arrayCtrls); return ret; }