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.

222 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. getdcname.cxx
  5. Abstract:
  6. getdcname
  7. Author:
  8. Larry Zhu (LZhu) December 1, 2001 Created
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #include "precomp.hxx"
  14. #pragma hdrstop
  15. #include <lm.h>
  16. #include <dsgetdc.h>
  17. #include "getdcname.hxx"
  18. BOOL
  19. DllMain(
  20. IN HANDLE hModule,
  21. IN DWORD dwReason,
  22. IN DWORD dwReserved
  23. )
  24. {
  25. return DllMainDefaultHandler(hModule, dwReason, dwReason);
  26. }
  27. #if 0
  28. Return Values for Start():
  29. ERROR_NO_MORE_USER_HANDLES unload repeatedly
  30. ERROR_SERVER_HAS_OPEN_HANDLES no unload at all
  31. others unload once
  32. #endif 0
  33. EXTERN_C
  34. NET_API_STATUS
  35. DsrGetDcNameEx2(
  36. IN LPWSTR ComputerName OPTIONAL,
  37. IN LPWSTR AccountName OPTIONAL,
  38. IN ULONG AllowableAccountControlBits,
  39. IN LPWSTR DomainName OPTIONAL,
  40. IN GUID* DomainGuid OPTIONAL,
  41. IN LPWSTR SiteName OPTIONAL,
  42. IN ULONG Flags,
  43. OUT PDOMAIN_CONTROLLER_INFOW *DomainControllerInfo
  44. );
  45. VOID
  46. PrintDcInfo(
  47. IN ULONG Level,
  48. IN PCTSTR pszBanner,
  49. IN PDOMAIN_CONTROLLER_INFO pDcInfo
  50. )
  51. {
  52. SspiPrint(Level,
  53. TEXT("%s: ClientSiteName %s, DcSiteName %s, DnsForestName %s, ")
  54. TEXT("DomainControllerAddress %s, DomainControllerAddressType %#x, ")
  55. TEXT("DomainControllerName %s, DomainName %s, Flags %#x\n"), pszBanner,
  56. pDcInfo->ClientSiteName,
  57. pDcInfo->DcSiteName,
  58. pDcInfo->DnsForestName,
  59. pDcInfo->DomainControllerAddress,
  60. pDcInfo->DomainControllerAddressType,
  61. pDcInfo->DomainControllerName,
  62. pDcInfo->DomainName,
  63. pDcInfo->Flags
  64. );
  65. SspiPrintHex(Level, pszBanner, sizeof(GUID), &pDcInfo->DomainGuid);
  66. }
  67. int
  68. Start(
  69. IN ULONG cbParameters,
  70. IN VOID* pvParameters
  71. )
  72. {
  73. // do your stuff
  74. THResult hRetval;
  75. UNICODE_STRING ServiceRealm = {0};
  76. PDOMAIN_CONTROLLER_INFO pDcInfo = NULL;
  77. ULONG Flags = (DS_KDC_REQUIRED | DS_IP_REQUIRED);
  78. hRetval DBGCHK = CreateUnicodeStringFromAsciiz((PCSTR) pvParameters, &ServiceRealm);
  79. if (SUCCEEDED(hRetval))
  80. {
  81. hRetval DBGCHK = HResultFromWin32(
  82. DsrGetDcNameEx2(
  83. NULL,
  84. NULL, // no account name
  85. UF_ACCOUNT_TYPE_MASK, // any account type
  86. ServiceRealm.Buffer,
  87. NULL, // no domain GUID
  88. NULL, // no site GUID,
  89. Flags,
  90. &pDcInfo
  91. ));
  92. }
  93. if (SUCCEEDED(hRetval))
  94. {
  95. PrintDcInfo(SSPI_LOG, TEXT("DsrGetDcNameEx2 DcInfo"), pDcInfo);
  96. if (pDcInfo)
  97. {
  98. NetApiBufferFree(pDcInfo);
  99. pDcInfo = NULL;
  100. }
  101. hRetval DBGCHK = HResultFromWin32(
  102. DsGetDcNameW(
  103. NULL,
  104. ServiceRealm.Buffer,
  105. NULL, // no domain GUID
  106. NULL, // no site GUID,
  107. Flags,
  108. &pDcInfo
  109. ));
  110. }
  111. if (SUCCEEDED(hRetval))
  112. {
  113. PrintDcInfo(SSPI_LOG, TEXT("DsGetDcNameW DcInfo"), pDcInfo);
  114. }
  115. if (pDcInfo)
  116. {
  117. NetApiBufferFree(pDcInfo);
  118. }
  119. RtlFreeUnicodeString(&ServiceRealm);
  120. return HRESULT_CODE(hRetval);
  121. }
  122. int
  123. RunIt(
  124. IN ULONG cbParameters,
  125. IN VOID* pvParameters
  126. )
  127. {
  128. //
  129. // RunItDefaultHandler calls Start() and adds try except
  130. //
  131. return RunItDefaultHandler(cbParameters, pvParameters);
  132. }
  133. int
  134. Init(
  135. IN ULONG argc,
  136. IN PCSTR argv[],
  137. OUT ULONG* pcbParameters,
  138. OUT VOID** ppvParameters
  139. )
  140. {
  141. DWORD dwErr = ERROR_SUCCESS;
  142. CHAR Parameters[REMOTE_PACKET_SIZE] = {0};
  143. ULONG cbBuffer = sizeof(Parameters);
  144. ULONG cbParameter = 0;
  145. DebugPrintf(SSPI_LOG, "Init: Hello world!\n");
  146. *pcbParameters = 0;
  147. *ppvParameters = NULL;
  148. if (argc == 1)
  149. {
  150. memcpy(Parameters + cbParameter, argv[0], strlen(argv[0]) + 1);
  151. cbParameter += strlen(argv[0]) + 1;
  152. cbParameter++; // add a NULL
  153. dwErr = ERROR_SUCCESS;
  154. }
  155. else // return "Usage" in ppvParameters, must be a NULL terminated string
  156. {
  157. strcpy(Parameters, "<domain name>");
  158. cbParameter = strlen(Parameters) + 1;
  159. dwErr = ERROR_INVALID_PARAMETER; // will display usage
  160. }
  161. *ppvParameters = new CHAR[cbParameter];
  162. if (*ppvParameters)
  163. {
  164. *pcbParameters = cbParameter;
  165. memcpy(*ppvParameters, Parameters, *pcbParameters);
  166. }
  167. else
  168. {
  169. dwErr = ERROR_OUTOFMEMORY;
  170. goto Cleanup;
  171. }
  172. #if 0
  173. dwErr = ERROR_CONTINUE; // use the default Init handler in injecter
  174. #endif
  175. Cleanup:
  176. return dwErr;
  177. }