Hi
Charles,
Thanks for replying.
I have
tried what you said - and I tried sorting on "cn" itself. But the results
remain unsorted. I am not sure if sorting itself is supported by AD or not. Have
you got successful sorted results EVER? If yes, I will have hope on my
side.
Here is the code.
bool LDAPH_ObjectSet::SortSelectedObjects( const
_TSTR strKeyAttribute )
{
LDAPSortKey **ppSortKeys = new LDAPSortKey
*[2];
ppSortKeys[0] = new
LDAPSortKey;
ppSortKeys[0]->sk_attrtype =
(_TCHAR*)strKeyAttribute.c_str();
ppSortKeys[0]->sk_matchruleoid =
LDAP_SERVER_SORT_OID_W;
ppSortKeys[0]->sk_reverseorder
= false;
ppSortKeys[1] = NULL;
LDAPControl *pLdapSortControl;
ULONG ulRes =
ldap_create_sort_control( m_pLdapSession->GetSessionHandle(),
ppSortKeys,
1,
&pLdapSortControl );
LDAPH_EXPECT_LDAP_SUCCESS(
ulRes );
LDAPControl **ppLdapControls
= new LDAPControl*[2];
ppLdapControls[0] =
pLdapSortControl;
ppLdapControls[1] = NULL;
// Erase previous Search
results.
if ( NULL !=
m_pSelectedObjects )
{
ldap_msgfree(m_pSelectedObjects);
m_pSelectedObjects = NULL;
}
ulRes = ldap_search_ext_s(
m_pLdapSession->GetSessionHandle(),
(_TCHAR *)
m_strBaseObjectDN.c_str(),
m_Level,
(_TCHAR*)m_strFilter.c_str(),
m_pptcsAttrs,
m_bAttribValues,
ppLdapControls,
NULL,
NULL,
0,
&m_pSelectedObjects );
ldap_control_free(
pLdapSortControl );
delete
ppSortKeys[0];
delete [] ppSortKeys;
delete [] ppLdapControls;
LDAPH_EXPECT_LDAP_SUCCESS(
ulRes );
return
true;
}
-sanju