Windows NT 4.0 source code leak
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.

139 lines
3.2 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. misc.c
  5. Abstract:
  6. this file provides the routine GetSystemType
  7. that returns an identifier for the system type
  8. i.e. NT on wrkgrp, domain or lMnt BDC, PDC.
  9. Author:
  10. Michael Montague (mikemon) 18-Dec-1991
  11. Revision History:
  12. --*/
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <ntlsa.h>
  17. #include "locsys.h"
  18. unsigned long
  19. GetSystemType(
  20. )
  21. /*
  22. Determine if we [locator] are being run on a Workgroup machine
  23. or a member machine or a PDC or a BDC
  24. */
  25. {
  26. NT_PRODUCT_TYPE NtProductType;
  27. LSA_HANDLE PolicyHandle;
  28. OBJECT_ATTRIBUTES ObjAttributes;
  29. PPOLICY_PRIMARY_DOMAIN_INFO PolicyPrimaryDomainInfo = NULL;
  30. PPOLICY_LSA_SERVER_ROLE_INFO PolicyLsaServerRoleInfo= NULL;
  31. NTSTATUS Status;
  32. unsigned long Role = ROLE_WKSTA_MEMBER;
  33. if( RtlGetNtProductType( &NtProductType ) )
  34. {
  35. InitializeObjectAttributes(
  36. &ObjAttributes,
  37. NULL,
  38. 0,
  39. NULL,
  40. NULL
  41. );
  42. Status = LsaOpenPolicy(
  43. NULL,
  44. &ObjAttributes,
  45. POLICY_VIEW_LOCAL_INFORMATION,
  46. &PolicyHandle
  47. );
  48. if (! NT_SUCCESS(Status) )
  49. goto CleanupAndLeave;
  50. if( NtProductType == NtProductWinNt )
  51. {
  52. //
  53. // the workstatation can Standalone or Member
  54. //
  55. Status = LsaQueryInformationPolicy(
  56. PolicyHandle,
  57. PolicyPrimaryDomainInformation,
  58. &PolicyPrimaryDomainInfo
  59. );
  60. if( NT_SUCCESS( Status ) )
  61. {
  62. if( PolicyPrimaryDomainInfo->Sid == NULL )
  63. {
  64. Role = ROLE_WKSTA_WKGRP;
  65. }
  66. else
  67. {
  68. Role = ROLE_WKSTA_MEMBER;
  69. }
  70. }
  71. }
  72. else
  73. {
  74. //
  75. // the role can be either RolePrimary or RoleBackup
  76. //
  77. Status = LsaQueryInformationPolicy(
  78. PolicyHandle,
  79. PolicyLsaServerRoleInformation,
  80. &PolicyLsaServerRoleInfo
  81. );
  82. if( NT_SUCCESS( Status ) )
  83. {
  84. if( PolicyLsaServerRoleInfo->LsaServerRole ==
  85. PolicyServerRoleBackup )
  86. {
  87. Role = ROLE_LMNT_BACKUPDC;
  88. }
  89. else
  90. {
  91. Role = ROLE_LMNT_PDC;
  92. }
  93. }
  94. }
  95. }
  96. CleanupAndLeave:
  97. if (PolicyPrimaryDomainInfo != NULL)
  98. LsaFreeMemory( PolicyPrimaryDomainInfo );
  99. if (PolicyLsaServerRoleInfo)
  100. LsaFreeMemory( PolicyLsaServerRoleInfo );
  101. return (Role);
  102. }