Source code of Windows XP (NT5)
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.

258 lines
4.4 KiB

  1. //--------------LDAP----------------------------------------------------------
  2. //
  3. //
  4. // Microsoft Windows
  5. // Copyright (C) Microsoft Corporation, 1992 - 1995
  6. //
  7. // File: cdssrch.cxx
  8. //
  9. // Contents: Microsoft ADs LDAP Provider Generic Object
  10. //
  11. //
  12. // History: 03-02-97 ShankSh Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "ldap.hxx"
  16. #include "stdio.h"
  17. #pragma hdrstop
  18. //
  19. // Sets the appropriate search preferences.
  20. //
  21. HRESULT
  22. CLDAPGenObject::SetSearchPreference(
  23. IN PADS_SEARCHPREF_INFO pSearchPrefs,
  24. IN DWORD dwNumPrefs
  25. )
  26. {
  27. HRESULT hr = S_OK;
  28. //
  29. // Need to initialize the searchprefs in case this fn
  30. // is being called for the 2nd time.
  31. //
  32. LdapInitializeSearchPreferences(&_SearchPref, TRUE);
  33. //
  34. // Make sure that the last error is reset
  35. //
  36. Macro_ClearADsLastError(L"LDAP Provider");
  37. hr = ADsSetSearchPreference(
  38. pSearchPrefs,
  39. dwNumPrefs,
  40. &_SearchPref,
  41. _pszLDAPServer,
  42. _pszLDAPDn,
  43. _Credentials,
  44. _dwPort
  45. );
  46. RRETURN(hr);
  47. }
  48. HRESULT
  49. CLDAPGenObject::ExecuteSearch(
  50. IN LPWSTR pszSearchFilter,
  51. IN LPWSTR * pAttributeNames,
  52. IN DWORD dwNumberAttributes,
  53. OUT PADS_SEARCH_HANDLE phSearchHandle
  54. )
  55. {
  56. HRESULT hr = S_OK;
  57. //
  58. // Make sure that the last error is reset
  59. //
  60. Macro_ClearADsLastError(L"LDAP Provider");
  61. hr = ADsExecuteSearch(
  62. _SearchPref,
  63. _ADsPath,
  64. _pszLDAPServer,
  65. _pszLDAPDn,
  66. pszSearchFilter,
  67. pAttributeNames,
  68. dwNumberAttributes,
  69. phSearchHandle
  70. );
  71. RRETURN(hr);
  72. }
  73. HRESULT
  74. CLDAPGenObject::AbandonSearch(
  75. IN ADS_SEARCH_HANDLE hSearchHandle
  76. )
  77. {
  78. HRESULT hr = S_OK;
  79. //
  80. // Make sure that the last error is reset
  81. //
  82. Macro_ClearADsLastError(L"LDAP Provider");
  83. hr = ADsAbandonSearch(
  84. hSearchHandle
  85. );
  86. RRETURN(hr);
  87. }
  88. HRESULT
  89. CLDAPGenObject::CloseSearchHandle (
  90. IN ADS_SEARCH_HANDLE hSearchHandle
  91. )
  92. {
  93. HRESULT hr = S_OK;
  94. //
  95. // Make sure that the last error is reset
  96. //
  97. Macro_ClearADsLastError(L"LDAP Provider");
  98. hr = ADsCloseSearchHandle(
  99. hSearchHandle
  100. );
  101. RRETURN(hr);
  102. }
  103. HRESULT
  104. CLDAPGenObject::GetFirstRow(
  105. IN ADS_SEARCH_HANDLE hSearchHandle
  106. )
  107. {
  108. HRESULT hr = S_OK;
  109. //
  110. // Make sure that the last error is reset
  111. //
  112. Macro_ClearADsLastError(L"LDAP Provider");
  113. hr = ADsGetFirstRow(
  114. hSearchHandle,
  115. _Credentials
  116. );
  117. RRETURN(hr);
  118. }
  119. HRESULT
  120. CLDAPGenObject::GetNextRow(
  121. IN ADS_SEARCH_HANDLE hSearchHandle
  122. )
  123. {
  124. HRESULT hr = S_OK;
  125. //
  126. // Make sure that the last error is reset
  127. //
  128. Macro_ClearADsLastError(L"LDAP Provider");
  129. hr = ADsGetNextRow(
  130. hSearchHandle,
  131. _Credentials
  132. );
  133. RRETURN(hr);
  134. }
  135. HRESULT
  136. CLDAPGenObject::GetPreviousRow(
  137. IN ADS_SEARCH_HANDLE hSearchHandle
  138. )
  139. {
  140. HRESULT hr = S_OK;
  141. //
  142. // Make sure that the last error is reset
  143. //
  144. Macro_ClearADsLastError(L"LDAP Provider");
  145. hr = ADsGetPreviousRow(
  146. hSearchHandle,
  147. _Credentials
  148. );
  149. RRETURN(hr);
  150. }
  151. HRESULT
  152. CLDAPGenObject::GetColumn(
  153. IN ADS_SEARCH_HANDLE hSearchHandle,
  154. IN LPWSTR pszColumnName,
  155. OUT PADS_SEARCH_COLUMN pColumn
  156. )
  157. {
  158. HRESULT hr = S_OK;
  159. //
  160. // Make sure that the last error is reset
  161. //
  162. Macro_ClearADsLastError(L"LDAP Provider");
  163. hr = ADsGetColumn(
  164. hSearchHandle,
  165. pszColumnName,
  166. _Credentials,
  167. _dwPort,
  168. pColumn
  169. );
  170. RRETURN(hr);
  171. }
  172. HRESULT
  173. CLDAPGenObject::GetNextColumnName(
  174. IN ADS_SEARCH_HANDLE hSearchHandle,
  175. OUT LPWSTR * ppszColumnName
  176. )
  177. {
  178. HRESULT hr = S_OK;
  179. //
  180. // Make sure that the last error is reset
  181. //
  182. Macro_ClearADsLastError(L"LDAP Provider");
  183. hr = ADsGetNextColumnName(
  184. hSearchHandle,
  185. ppszColumnName
  186. );
  187. RRETURN(hr);
  188. }
  189. HRESULT
  190. CLDAPGenObject::FreeColumn(
  191. IN PADS_SEARCH_COLUMN pColumn
  192. )
  193. {
  194. HRESULT hr = S_OK;
  195. //
  196. // Make sure that the last error is reset
  197. //
  198. Macro_ClearADsLastError(L"LDAP Provider");
  199. hr = ADsFreeColumn(
  200. pColumn
  201. );
  202. RRETURN(hr);
  203. }