未验证 提交 66165e63 编写于 作者: J Jiri Formacek 提交者: GitHub

Ldap search crashes on Linux when timeout specified (#72676)

上级 8b1aecb7
......@@ -122,7 +122,7 @@ static Ldap()
[MarshalAs(UnmanagedType.Bool)] bool attributeOnly,
IntPtr servercontrol,
IntPtr clientcontrol,
int timelimit,
in LDAP_TIMEVAL timelimit,
int sizelimit,
ref int messageNumber);
......
......@@ -90,9 +90,20 @@ internal static int ParseResultReferral(ConnectionHandle ldapHandle, IntPtr resu
internal static int ResultToErrorCode(ConnectionHandle ldapHandle, IntPtr result, int freeIt) => Interop.Ldap.ldap_result2error(ldapHandle, result, freeIt);
internal static int SearchDirectory(ConnectionHandle ldapHandle, string dn, int scope, string filter, IntPtr attributes, bool attributeOnly, IntPtr servercontrol, IntPtr clientcontrol, int timelimit, int sizelimit, ref int messageNumber) =>
Interop.Ldap.ldap_search(ldapHandle, dn, scope, filter, attributes, attributeOnly, servercontrol, clientcontrol, timelimit, sizelimit, ref messageNumber);
internal static int SearchDirectory(ConnectionHandle ldapHandle, string dn, int scope, string filter, IntPtr attributes, bool attributeOnly, IntPtr servercontrol, IntPtr clientcontrol, int timelimit, int sizelimit, ref int messageNumber)
{
LDAP_TIMEVAL searchTimeout = new LDAP_TIMEVAL
{
tv_sec = timelimit
};
//zero must not be passed otherwise libldap runtime returns LDAP_PARAM_ERROR
if (searchTimeout.tv_sec < 1)
//-1 means no time limit
searchTimeout.tv_sec = -1;
return Interop.Ldap.ldap_search(ldapHandle, dn, scope, filter, attributes, attributeOnly, servercontrol, clientcontrol, searchTimeout, sizelimit, ref messageNumber);
}
internal static int SetBoolOption(ConnectionHandle ld, LdapOption option, bool value) => Interop.Ldap.ldap_set_option_bool(ld, option, value);
// This option is not supported in Linux, so it would most likely throw.
......
......@@ -74,6 +74,26 @@ public void TestUnavailableNonCriticalExtension()
_ = (SearchResponse) connection.SendRequest(searchRequest);
// Does not throw
}
[InlineData(60)]
[InlineData(0)]
[InlineData(-60)]
[ConditionalTheory(nameof(IsLdapConfigurationExist))]
public void TestSearchWithTimeLimit(int timeLimit)
{
using LdapConnection connection = GetConnection();
var searchRequest = new SearchRequest(LdapConfiguration.Configuration.SearchDn, "(objectClass=*)", SearchScope.Subtree);
if (timeLimit < 0)
{
Assert.Throws<ArgumentException>(() => searchRequest.TimeLimit = TimeSpan.FromSeconds(timeLimit));
}
else
{
searchRequest.TimeLimit = TimeSpan.FromSeconds(timeLimit);
_ = (SearchResponse)connection.SendRequest(searchRequest);
// Shall succeed
}
}
[ConditionalFact(nameof(IsLdapConfigurationExist))]
public void TestAddingOU()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册