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.

163 lines
3.6 KiB

  1. //+--------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996-1996
  5. //
  6. // File: svcrole.c
  7. //
  8. // Contents: This is the include to include common we need
  9. //
  10. // History:
  11. //
  12. //---------------------------------------------------------------------------
  13. #include "svcrole.h"
  14. #include "secstore.h"
  15. #include <dsgetdc.h>
  16. #include <dsrole.h>
  17. ///////////////////////////////////////////////////////////////////////////////////
  18. BOOL
  19. GetMachineGroup(
  20. LPWSTR pszMachineName,
  21. LPWSTR* pszGroupName
  22. )
  23. /*++
  24. Note:
  25. Code modified from DISPTRUS.C
  26. --*/
  27. {
  28. LSA_HANDLE PolicyHandle;
  29. DWORD dwStatus;
  30. NTSTATUS Status;
  31. NET_API_STATUS nas = NERR_Success; // assume success
  32. BOOL bSuccess = FALSE; // assume this function will fail
  33. PPOLICY_PRIMARY_DOMAIN_INFO PrimaryDomain = NULL;
  34. LPWSTR szPrimaryDomainName = NULL;
  35. LPWSTR DomainController = NULL;
  36. //
  37. // open the policy on the specified machine
  38. //
  39. Status = OpenPolicy(
  40. pszMachineName,
  41. POLICY_VIEW_LOCAL_INFORMATION,
  42. &PolicyHandle
  43. );
  44. if(Status != ERROR_SUCCESS)
  45. {
  46. SetLastError( dwStatus = LsaNtStatusToWinError(Status) );
  47. return FALSE;
  48. }
  49. //
  50. // get the primary domain
  51. //
  52. Status = LsaQueryInformationPolicy(
  53. PolicyHandle,
  54. PolicyPrimaryDomainInformation,
  55. (PVOID *)&PrimaryDomain
  56. );
  57. if(Status != ERROR_SUCCESS)
  58. {
  59. goto cleanup;
  60. }
  61. *pszGroupName = (LPWSTR)LocalAlloc(
  62. LPTR,
  63. PrimaryDomain->Name.Length + sizeof(WCHAR) // existing length + NULL
  64. );
  65. if(*pszGroupName != NULL)
  66. {
  67. //
  68. // copy the existing buffer to the new storage, appending a NULL
  69. //
  70. lstrcpynW(
  71. *pszGroupName,
  72. PrimaryDomain->Name.Buffer,
  73. (PrimaryDomain->Name.Length / sizeof(WCHAR)) + 1
  74. );
  75. bSuccess = TRUE;
  76. }
  77. cleanup:
  78. if(PrimaryDomain != NULL)
  79. {
  80. LsaFreeMemory(PrimaryDomain);
  81. }
  82. //
  83. // close the policy handle
  84. //
  85. if(PolicyHandle != INVALID_HANDLE_VALUE)
  86. {
  87. LsaClose(PolicyHandle);
  88. }
  89. if(!bSuccess)
  90. {
  91. if(Status != ERROR_SUCCESS)
  92. {
  93. SetLastError( LsaNtStatusToWinError(Status) );
  94. }
  95. else if(nas != NERR_Success)
  96. {
  97. SetLastError( nas );
  98. }
  99. }
  100. return bSuccess;
  101. }
  102. ///////////////////////////////////////////////////////////////////////////////////
  103. BOOL
  104. IsDomainController(
  105. LPWSTR Server,
  106. LPBOOL bDomainController
  107. )
  108. /*++
  109. ++*/
  110. {
  111. PSERVER_INFO_101 si101;
  112. NET_API_STATUS nas;
  113. nas = NetServerGetInfo( (LPTSTR)Server,
  114. 101,
  115. (LPBYTE *)&si101 );
  116. if(nas != NERR_Success)
  117. {
  118. SetLastError(nas);
  119. return FALSE;
  120. }
  121. if( (si101->sv101_type & SV_TYPE_DOMAIN_CTRL) ||
  122. (si101->sv101_type & SV_TYPE_DOMAIN_BAKCTRL) )
  123. {
  124. // we are dealing with a DC
  125. //
  126. *bDomainController = TRUE;
  127. }
  128. else
  129. {
  130. *bDomainController = FALSE;
  131. }
  132. NetApiBufferFree(si101);
  133. return TRUE;
  134. }