Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

139 lines
2.9 KiB

  1. #include "headers.h"
  2. CDSSearch::
  3. CDSSearch(CComPtr<IDirectorySearch>& refspSearchObject):
  4. m_pObj(refspSearchObject)
  5. {
  6. m_ppszAttr = NULL;
  7. m_CountAttr = NULL;
  8. m_SearchHandle = NULL;
  9. m_scope = ADS_SCOPE_SUBTREE;
  10. }
  11. void
  12. CDSSearch::
  13. _Reset()
  14. {
  15. if (m_SearchHandle)
  16. {
  17. m_pObj->CloseSearchHandle(m_SearchHandle);
  18. m_SearchHandle = NULL;
  19. }
  20. }
  21. CDSSearch::
  22. ~CDSSearch()
  23. {
  24. _Reset();
  25. }
  26. HRESULT
  27. CDSSearch::
  28. SetAttributeList(LPTSTR *ppszAttribs, INT cAttrs)
  29. {
  30. m_ppszAttr = ppszAttribs;
  31. m_CountAttr = cAttrs;
  32. return S_OK;
  33. }
  34. HRESULT
  35. CDSSearch::
  36. SetSearchScope (ADS_SCOPEENUM scope)
  37. {
  38. m_scope = scope;
  39. return S_OK;
  40. }
  41. const int NUM_PREFS = 5;
  42. HRESULT
  43. _SetSearchPreference(IDirectorySearch* piSearch,
  44. ADS_SCOPEENUM scope,
  45. BOOL bAttrOnly)
  46. {
  47. if (NULL == piSearch)
  48. {
  49. ASSERT(FALSE);
  50. return E_INVALIDARG;
  51. }
  52. int cPref = 4;
  53. ADS_SEARCHPREF_INFO aSearchPref[5];
  54. aSearchPref[0].dwSearchPref = ADS_SEARCHPREF_CHASE_REFERRALS;
  55. aSearchPref[0].vValue.dwType = ADSTYPE_INTEGER;
  56. aSearchPref[0].vValue.Integer = ADS_CHASE_REFERRALS_EXTERNAL;
  57. aSearchPref[1].dwSearchPref = ADS_SEARCHPREF_PAGESIZE;
  58. aSearchPref[1].vValue.dwType = ADSTYPE_INTEGER;
  59. aSearchPref[1].vValue.Integer = QUERY_PAGESIZE;
  60. aSearchPref[2].dwSearchPref = ADS_SEARCHPREF_CACHE_RESULTS;
  61. aSearchPref[2].vValue.dwType = ADSTYPE_BOOLEAN;
  62. aSearchPref[2].vValue.Integer = FALSE;
  63. aSearchPref[3].dwSearchPref = ADS_SEARCHPREF_SEARCH_SCOPE;
  64. aSearchPref[3].vValue.dwType = ADSTYPE_INTEGER;
  65. aSearchPref[3].vValue.Integer = scope;
  66. if(bAttrOnly)
  67. {
  68. aSearchPref[4].dwSearchPref = ADS_SEARCHPREF_ATTRIBTYPES_ONLY;
  69. aSearchPref[4].vValue.dwType = ADSTYPE_BOOLEAN;
  70. aSearchPref[4].vValue.Integer = TRUE;
  71. ++cPref;
  72. }
  73. return piSearch->SetSearchPreference (aSearchPref, cPref);
  74. }
  75. HRESULT CDSSearch::DoQuery(BOOL bAttrOnly)
  76. {
  77. HRESULT hr = _SetSearchPreference(m_pObj, m_scope, bAttrOnly);
  78. if (SUCCEEDED(hr)) {
  79. hr = m_pObj->ExecuteSearch ((LPWSTR)(LPCTSTR)m_strFilter,
  80. m_ppszAttr,
  81. m_CountAttr,
  82. &m_SearchHandle);
  83. }
  84. return hr;
  85. }
  86. HRESULT
  87. CDSSearch::
  88. GetNextRow()
  89. {
  90. DWORD status = ERROR_MORE_DATA;
  91. HRESULT hr = S_OK;
  92. HRESULT hr2 = S_OK;
  93. WCHAR Buffer1[512], Buffer2[512];
  94. while (status == ERROR_MORE_DATA )
  95. {
  96. hr = m_pObj->GetNextRow (m_SearchHandle);
  97. if (hr == S_ADS_NOMORE_ROWS)
  98. {
  99. hr2 = ADsGetLastError(&status, Buffer1, 512,
  100. Buffer2, 512);
  101. ASSERT(SUCCEEDED(hr2));
  102. } else
  103. {
  104. status = 0;
  105. }
  106. }
  107. return hr;
  108. }
  109. HRESULT
  110. CDSSearch::
  111. GetColumn(LPWSTR Attribute,
  112. PADS_SEARCH_COLUMN pColumnData)
  113. {
  114. return m_pObj->GetColumn (m_SearchHandle,
  115. Attribute,
  116. pColumnData);
  117. }
  118. HRESULT
  119. CDSSearch::GetNextColumnName(LPWSTR *ppszColumnName)
  120. {
  121. return m_pObj->GetNextColumnName(m_SearchHandle,
  122. ppszColumnName);
  123. }