* autoload.cc (ldap_abandon): Remove.

(ldap_count_entries): Import.
	(ldap_get_next_page_s): Import.
	(ldap_result): Remove.
	(ldap_searchW): Remove.
	(ldap_search_abandon_page): Import.
	(ldap_search_init_pageW): Import.
	* ldap.cc (cyg_ldap::close): Use ldap_search_abandon_page to abandon
	search.  Reset srch_id, srch_msg and srch_entry.
	(cyg_ldap::enumerate_ad_accounts): Use paged search to overcome server
	side search result set restriction.
	(cyg_ldap::next_account): Ditto.
	* ldap.h (class cyg_ldap): Add members srch_id, srch_msg and srch_entry.
	Remove member msg_id.
	(cyg_ldap::cyg_ldap): Change initialization accordingly.
This commit is contained in:
Corinna Vinschen 2014-05-22 20:07:25 +00:00
parent de13ccea73
commit 449429c16a
4 changed files with 59 additions and 30 deletions

View File

@ -1,3 +1,21 @@
2014-05-22 Corinna Vinschen <corinna@vinschen.de>
* autoload.cc (ldap_abandon): Remove.
(ldap_count_entries): Import.
(ldap_get_next_page_s): Import.
(ldap_result): Remove.
(ldap_searchW): Remove.
(ldap_search_abandon_page): Import.
(ldap_search_init_pageW): Import.
* ldap.cc (cyg_ldap::close): Use ldap_search_abandon_page to abandon
search. Reset srch_id, srch_msg and srch_entry.
(cyg_ldap::enumerate_ad_accounts): Use paged search to overcome server
side search result set restriction.
(cyg_ldap::next_account): Ditto.
* ldap.h (class cyg_ldap): Add members srch_id, srch_msg and srch_entry.
Remove member msg_id.
(cyg_ldap::cyg_ldap): Change initialization accordingly.
2014-05-22 Corinna Vinschen <corinna@vinschen.de>
* sec_auth.cc (get_server_groups): Call get_user_local_groups only if

View File

@ -585,17 +585,18 @@ LoadDLLfunc (LocaleNameToLCID, 8, kernel32)
#pragma push_macro ("mangle")
#undef mangle
#define mangle(name, n) #name
LoadDLLfunc (ldap_abandon, 0, wldap32)
LoadDLLfunc (ldap_bind_s, 0, wldap32)
LoadDLLfunc (ldap_count_entries, 0, wldap32)
LoadDLLfunc (ldap_count_valuesW, 0, wldap32)
LoadDLLfunc (ldap_first_entry, 0, wldap32)
LoadDLLfunc (ldap_get_next_page_s, 0, wldap32)
LoadDLLfunc (ldap_get_valuesW, 0, wldap32)
LoadDLLfunc (ldap_get_values_lenW, 0, wldap32)
LoadDLLfunc (ldap_initW, 0, wldap32)
LoadDLLfunc (ldap_memfreeW, 0, wldap32)
LoadDLLfunc (ldap_next_entry, 0, wldap32)
LoadDLLfunc (ldap_result, 0, wldap32)
LoadDLLfunc (ldap_searchW, 0, wldap32)
LoadDLLfunc (ldap_search_abandon_page, 0, wldap32)
LoadDLLfunc (ldap_search_init_pageW, 0, wldap32)
LoadDLLfunc (ldap_search_stW, 0, wldap32)
LoadDLLfunc (ldap_set_option, 0, wldap32)
LoadDLLfunc (ldap_sslinitW, 0, wldap32)

View File

@ -182,10 +182,12 @@ err:
void
cyg_ldap::close ()
{
if (msg_id != (ULONG) -1)
ldap_abandon (lh, msg_id);
if (srch_id != NULL)
ldap_search_abandon_page (lh, srch_id);
if (lh)
ldap_unbind (lh);
if (srch_msg)
ldap_memfreeW ((PWCHAR) srch_msg);
if (msg)
ldap_memfreeW ((PWCHAR) msg);
if (val)
@ -196,7 +198,8 @@ cyg_ldap::close ()
msg = entry = NULL;
val = NULL;
rootdse = NULL;
msg_id = (ULONG) -1;
srch_id = NULL;
srch_msg = srch_entry = NULL;
}
bool
@ -286,12 +289,13 @@ cyg_ldap::enumerate_ad_accounts (PCWSTR domain, bool group)
/* 1 == ACCOUNT_GROUP */
"(!(groupType:" LDAP_MATCHING_RULE_BIT_AND ":=1))"
"(objectSid=*))";
msg_id = ldap_searchW (lh, rootdse, LDAP_SCOPE_SUBTREE, (PWCHAR) filter,
sid_attr, 0);
if (msg_id == (ULONG) -1)
srch_id = ldap_search_init_pageW (lh, rootdse, LDAP_SCOPE_SUBTREE,
(PWCHAR) filter, sid_attr, 0,
NULL, NULL, 3, 100, NULL);
if (srch_id == NULL)
{
debug_printf ("ldap_searchW(%W,%W) error 0x%02x", rootdse, filter,
LdapGetLastError ());
debug_printf ("ldap_search_init_pageW(%W,%W) error 0x%02x",
rootdse, filter, LdapGetLastError ());
return false;
}
return true;
@ -303,29 +307,34 @@ cyg_ldap::next_account (cygsid &sid)
ULONG ret;
PLDAP_BERVAL *bval;
if (msg)
ULONG total;
if (srch_entry)
{
ldap_memfreeW ((PWCHAR) msg);
msg = entry = NULL;
if ((srch_entry = ldap_next_entry (lh, srch_entry))
&& (bval = ldap_get_values_lenW (lh, srch_entry, sid_attr[0])))
{
sid = (PSID) bval[0]->bv_val;
ldap_value_free_len (bval);
return true;
}
ldap_memfreeW ((PWCHAR) srch_msg);
srch_msg = srch_entry = NULL;
}
if (val)
do
{
ldap_value_freeW (val);
val = NULL;
ret = ldap_get_next_page_s (lh, srch_id, &tv, 100, &total, &srch_msg);
}
ret = ldap_result (lh, msg_id, LDAP_MSG_ONE, &tv, &msg);
if (ret == 0)
while (ret == LDAP_SUCCESS && ldap_count_entries (lh, srch_msg) == 0);
if (ret == LDAP_NO_RESULTS_RETURNED)
return false;
if (ret != LDAP_SUCCESS)
{
debug_printf ("ldap_result() timeout!");
debug_printf ("ldap_result() error 0x%02x", ret);
return false;
}
if (ret == (ULONG) -1)
{
debug_printf ("ldap_result() error 0x%02x", LdapGetLastError ());
return false;
}
if ((entry = ldap_first_entry (lh, msg))
&& (bval = ldap_get_values_lenW (lh, entry, sid_attr[0])))
if ((srch_entry = ldap_first_entry (lh, srch_msg))
&& (bval = ldap_get_values_lenW (lh, srch_entry, sid_attr[0])))
{
sid = (PSID) bval[0]->bv_val;
ldap_value_free_len (bval);

View File

@ -33,7 +33,8 @@ class cyg_ldap {
PWCHAR *val;
PWCHAR *attr;
bool isAD;
ULONG msg_id;
PLDAPSearch srch_id;
PLDAPMessage srch_msg, srch_entry;
bool connect_ssl (PCWSTR domain);
bool connect_non_ssl (PCWSTR domain);
@ -43,8 +44,8 @@ class cyg_ldap {
uint32_t get_num_attribute (int idx);
public:
cyg_ldap () : lh (NULL), rootdse (NULL), msg (NULL), entry (NULL),
val (NULL), isAD (false), msg_id ((ULONG) -1)
cyg_ldap () : lh (NULL), rootdse (NULL), msg (NULL), entry (NULL), val (NULL),
isAD (false), srch_id (NULL), srch_msg (NULL), srch_entry (NULL)
{}
~cyg_ldap () { close (); }