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.

104 lines
2.1 KiB

  1. #include <windows.h>
  2. #include <userenv.h>
  3. #include <tchar.h>
  4. #include <stdio.h>
  5. #include <dsgetdc.h>
  6. #include <lm.h>
  7. #define SECURITY_WIN32
  8. #include <security.h>
  9. int __cdecl main( int argc, char *argv[])
  10. {
  11. HANDLE hToken;
  12. DWORD dwStart, dwDelta;
  13. PGROUP_POLICY_OBJECT pGPOList, pTemp;
  14. TCHAR szName[200];
  15. TCHAR szDCName[200];
  16. ULONG ulSize;
  17. DWORD dwResult;
  18. PDOMAIN_CONTROLLER_INFO pDCI = NULL;
  19. OpenProcessToken (GetCurrentProcess(), TOKEN_ALL_ACCESS, &hToken);
  20. dwStart = GetTickCount();
  21. if (GetGPOList (hToken, NULL, NULL, NULL, 0, &pGPOList)) {
  22. dwDelta = GetTickCount() - dwStart;
  23. _tprintf (TEXT("\r\nTick count: %d\r\n\r\n"), dwDelta);
  24. pTemp = pGPOList;
  25. while (pTemp) {
  26. _tprintf (TEXT("%s\t%s\r\n"), pTemp->szGPOName, pTemp->lpDisplayName);
  27. pTemp = pTemp->pNext;
  28. }
  29. FreeGPOList (pGPOList);
  30. }
  31. CloseHandle (hToken);
  32. //
  33. // Second time without the hToken
  34. //
  35. _tprintf (TEXT("\r\n\r\nRound 2 without token\r\n\r\n"));
  36. ulSize = 200;
  37. if (!GetUserNameEx (NameFullyQualifiedDN, szName, &ulSize)) {
  38. return 0;
  39. }
  40. //
  41. // Check this domain for a DC
  42. //
  43. dwResult = DsGetDcName (NULL, NULL, NULL, NULL,
  44. DS_DIRECTORY_SERVICE_PREFERRED, &pDCI);
  45. if (dwResult != ERROR_SUCCESS) {
  46. return 0;
  47. }
  48. //
  49. // Found a DC, does it have a DS ?
  50. //
  51. if (!(pDCI->Flags & DS_DS_FLAG)) {
  52. NetApiBufferFree(pDCI);
  53. return 0;
  54. }
  55. dwStart = GetTickCount();
  56. if (GetGPOList (NULL, szName, pDCI->DomainControllerName, NULL, 0, &pGPOList)) {
  57. dwDelta = GetTickCount() - dwStart;
  58. _tprintf (TEXT("\r\nTick count: %d\r\n\r\n"), dwDelta);
  59. pTemp = pGPOList;
  60. while (pTemp) {
  61. _tprintf (TEXT("%s\t%s\r\n"), pTemp->szGPOName, pTemp->lpDisplayName);
  62. pTemp = pTemp->pNext;
  63. }
  64. FreeGPOList (pGPOList);
  65. }
  66. NetApiBufferFree(pDCI);
  67. return 0;
  68. }