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.

94 lines
3.5 KiB

  1. #include "stdafx.h"
  2. #include "qrythrd.h"
  3. HRESULT
  4. IssueQuery(LPTHREADDATA ptd)
  5. {
  6. HRESULT hres;
  7. DWORD dwres;
  8. LPTHREADINITDATA ptid = ptd->ptid;
  9. LPWSTR pQuery = NULL;
  10. INT cItems, iColumn;
  11. INT cMaxResult = MAX_RESULT;
  12. BOOL fStopQuery = FALSE;
  13. IDirectorySearch* pDsSearch = NULL;
  14. LPWSTR pszTempPath = NULL;
  15. IDsDisplaySpecifier *pdds = NULL;
  16. ADS_SEARCH_HANDLE hSearch = NULL;
  17. ADS_SEARCHPREF_INFO prefInfo[3];
  18. ADS_SEARCH_COLUMN column;
  19. HDPA hdpaResults = NULL;
  20. LPQUERYRESULT pResult = NULL;
  21. WCHAR szBuffer[2048]; // MAX_URL_LENGHT
  22. INT resid;
  23. LPWSTR pColumnData = NULL;
  24. HKEY hkPolicy = NULL;
  25. USES_CONVERSION;
  26. TraceEnter(TRACE_QUERYTHREAD, "QueryThread_IssueQuery");
  27. // The foreground gave us a query so we are going to go and issue
  28. // it now, having done this we will then be able to stream the
  29. // result blobs back to the caller.
  30. hres = QueryThread_GetFilter(&pQuery, ptid->pQuery, ptid->fShowHidden);
  31. FailGracefully(hres, "Failed to build LDAP query from scope, parameters + filter");
  32. Trace(TEXT("Query is: %s"), W2T(pQuery));
  33. Trace(TEXT("Scope is: %s"), W2T(ptid->pScope));
  34. // Get the IDsDisplaySpecifier interface:
  35. hres = CoCreateInstance(CLSID_DsDisplaySpecifier, NULL, CLSCTX_INPROC_SERVER, IID_IDsDisplaySpecifier, (void **)&pdds);
  36. FailGracefully(hres, "Failed to get the IDsDisplaySpecifier object");
  37. hres = pdds->SetServer(ptid->pServer, ptid->pUserName, ptid->pPassword, DSSSF_DSAVAILABLE);
  38. FailGracefully(hres, "Failed to server information");
  39. // initialize the query engine, specifying the scope, and the search parameters
  40. hres = QueryThread_BuildPropertyList(ptd);
  41. FailGracefully(hres, "Failed to build property array to query for");
  42. hres = ADsOpenObject(ptid->pScope, ptid->pUserName, ptid->pPassword, ADS_SECURE_AUTHENTICATION,
  43. IID_IDirectorySearch, (LPVOID*)&pDsSearch);
  44. FailGracefully(hres, "Failed to get the IDirectorySearch interface for the given scope");
  45. prefInfo[0].dwSearchPref = ADS_SEARCHPREF_SEARCH_SCOPE; // sub-tree search
  46. prefInfo[0].vValue.dwType = ADSTYPE_INTEGER;
  47. prefInfo[0].vValue.Integer = ADS_SCOPE_SUBTREE;
  48. prefInfo[1].dwSearchPref = ADS_SEARCHPREF_ASYNCHRONOUS; // async
  49. prefInfo[1].vValue.dwType = ADSTYPE_BOOLEAN;
  50. prefInfo[1].vValue.Boolean = TRUE;
  51. prefInfo[2].dwSearchPref = ADS_SEARCHPREF_PAGESIZE; // paged results
  52. prefInfo[2].vValue.dwType = ADSTYPE_INTEGER;
  53. prefInfo[2].vValue.Integer = PAGE_SIZE;
  54. hres = pDsSearch->SetSearchPreference(prefInfo, ARRAYSIZE(prefInfo));
  55. FailGracefully(hres, "Failed to set search preferences");
  56. hres = pDsSearch->ExecuteSearch(pQuery, ptd->aProperties, ptd->cProperties, &hSearch);
  57. FailGracefully(hres, "Failed in ExecuteSearch");
  58. // pick up the policy value which defines the max results we are going to use
  59. dwres = RegOpenKey(HKEY_CURRENT_USER, DS_POLICY, &hkPolicy);
  60. if ( ERROR_SUCCESS == dwres )
  61. {
  62. DWORD dwType, cbSize;
  63. dwres = RegQueryValueEx(hkPolicy, TEXT("QueryLimit"), NULL, &dwType, NULL, &cbSize);
  64. if ( (ERROR_SUCCESS == dwres) && (dwType == REG_DWORD) && (cbSize == SIZEOF(cMaxResult)) )
  65. {
  66. RegQueryValueEx(hkPolicy, TEXT("QueryLimit"), NULL, NULL, (LPBYTE)&cMaxResult, &cbSize);
  67. }
  68. RegCloseKey(hkPolicy);
  69. }