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.

141 lines
3.3 KiB

  1. // QryBase.cpp : Implementation of ds routines and classes
  2. //+-------------------------------------------------------------------------
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 1992 - 1999
  6. //
  7. // File: qrybase.cpp
  8. //
  9. // Contents: DS Enumeration routines and classes
  10. //
  11. // History: 02-Oct-96 WayneSc Created
  12. // 08-Apr-98 JonN Copied from DSADMIN QUERYSUP.CPP
  13. //
  14. //
  15. //--------------------------------------------------------------------------
  16. #include "pch.h"
  17. #include "qrybase.h"
  18. ///////////////////////////////////////////////////////////////////////////////
  19. CDSSearch::CDSSearch()
  20. {
  21. m_bInitialized = FALSE;
  22. m_pwszFilter = NULL;
  23. m_pObj = NULL;
  24. m_SearchHandle = NULL;
  25. }
  26. CDSSearch::~CDSSearch()
  27. {
  28. if (m_pObj != NULL) {
  29. if (m_SearchHandle) {
  30. m_pObj->CloseSearchHandle (m_SearchHandle);
  31. }
  32. m_pObj->Release();
  33. }
  34. }
  35. HRESULT CDSSearch::Init(IDirectorySearch * pObj)
  36. {
  37. HRESULT hr = S_OK;
  38. m_pObj = pObj;
  39. pObj->AddRef();
  40. m_bInitialized = TRUE;
  41. return hr;
  42. }
  43. HRESULT CDSSearch::Init(LPCWSTR lpcszObjectPath)
  44. {
  45. HRESULT hr;
  46. hr = DSAdminOpenObject(const_cast<LPWSTR>(lpcszObjectPath),
  47. IID_IDirectorySearch,
  48. (void **)&m_pObj);
  49. if (SUCCEEDED(hr)) {
  50. m_bInitialized = TRUE;
  51. } else {
  52. m_bInitialized = FALSE;
  53. m_pObj = NULL;
  54. }
  55. return hr;
  56. }
  57. HRESULT CDSSearch::SetAttributeList (LPWSTR *pszAttribs, INT cAttrs)
  58. {
  59. m_pszAttribs = pszAttribs;
  60. m_nAttrs = cAttrs;
  61. return S_OK;
  62. }
  63. HRESULT CDSSearch::SetSearchScope (ADS_SCOPEENUM scope)
  64. {
  65. ADS_SEARCHPREF_INFO aSearchPref;
  66. HRESULT hr;
  67. if (m_bInitialized) {
  68. aSearchPref.dwSearchPref = ADS_SEARCHPREF_SEARCH_SCOPE;
  69. aSearchPref.vValue.dwType = ADSTYPE_INTEGER;
  70. aSearchPref.vValue.Integer = scope;
  71. return hr = m_pObj->SetSearchPreference (&aSearchPref, 1);
  72. } else {
  73. return E_ADS_BAD_PATHNAME;
  74. }
  75. }
  76. const int NUM_PREFS=2;
  77. HRESULT CDSSearch::DoQuery()
  78. {
  79. HRESULT hr;
  80. ADS_SEARCHPREF_INFO aSearchPref[NUM_PREFS];
  81. if (m_bInitialized) {
  82. aSearchPref[0].dwSearchPref = ADS_SEARCHPREF_CHASE_REFERRALS;
  83. aSearchPref[0].vValue.dwType = ADSTYPE_INTEGER;
  84. aSearchPref[0].vValue.Integer = ADS_CHASE_REFERRALS_EXTERNAL;
  85. aSearchPref[1].dwSearchPref = ADS_SEARCHPREF_PAGESIZE;
  86. aSearchPref[1].vValue.dwType = ADSTYPE_INTEGER;
  87. aSearchPref[1].vValue.Integer = QUERY_PAGESIZE;
  88. hr = m_pObj->SetSearchPreference (aSearchPref, NUM_PREFS);
  89. if (SUCCEEDED(hr)) {
  90. hr = m_pObj->ExecuteSearch (m_pwszFilter,
  91. m_pszAttribs,
  92. m_nAttrs,
  93. &m_SearchHandle);
  94. }
  95. } else {
  96. hr = E_ADS_BAD_PATHNAME;
  97. }
  98. return hr;
  99. }
  100. HRESULT
  101. CDSSearch::GetNextRow()
  102. {
  103. if (m_bInitialized) {
  104. return m_pObj->GetNextRow (m_SearchHandle);
  105. }
  106. return E_ADS_BAD_PATHNAME;
  107. }
  108. HRESULT
  109. CDSSearch::GetColumn(LPWSTR Attribute,
  110. PADS_SEARCH_COLUMN pColumnData)
  111. {
  112. if (m_bInitialized) {
  113. return m_pObj->GetColumn (m_SearchHandle,
  114. Attribute,
  115. pColumnData);
  116. }
  117. return E_ADS_BAD_PATHNAME;
  118. }