Source code of Windows XP (NT5)
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.

146 lines
3.0 KiB

  1. /*++
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. dsrole.c
  5. Abstract:
  6. utility to dump output of DsRoleGetPrimaryDomainInformation
  7. Author:
  8. Charlie Wickham (charlwi) 03-Nov-00
  9. Environment:
  10. User mode
  11. Revision History:
  12. --*/
  13. #define UNICODE 1
  14. #define _UNICODE 1
  15. #include <windows.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <dsrole.h>
  19. PWSTR RoleNames[] = {
  20. L"StandaloneWorkstation",
  21. L"MemberWorkstation",
  22. L"StandaloneServer",
  23. L"MemberServer",
  24. L"BackupDomainController",
  25. L"PrimaryDomainController "
  26. };
  27. typedef struct _FLAG_DATA {
  28. ULONG Flag;
  29. PWCHAR Name;
  30. } FLAG_DATA;
  31. FLAG_DATA FlagData[] = {
  32. { DSROLE_PRIMARY_DS_RUNNING, L"DS running on this node" },
  33. { DSROLE_PRIMARY_DS_MIXED_MODE, L"DS running in mixed mode" },
  34. { DSROLE_UPGRADE_IN_PROGRESS, L"Node is upgrading" },
  35. { DSROLE_PRIMARY_DOMAIN_GUID_PRESENT, L"Valid GUID" }
  36. };
  37. typedef WCHAR GUIDSTR[32 * 3];
  38. VOID formatGuid(LPGUID Guid, PWCHAR buf)
  39. {
  40. //
  41. // GUIDs look like this: 4082164E-A4B5-11D2-89C3-E37CB6BB13FC
  42. //
  43. wsprintfW(
  44. buf,
  45. L"%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X",
  46. Guid->Data1, Guid->Data2, Guid->Data3,
  47. Guid->Data4[0], Guid->Data4[1], Guid->Data4[2], Guid->Data4[3],
  48. Guid->Data4[4], Guid->Data4[5], Guid->Data4[6], Guid->Data4[7]
  49. );
  50. }
  51. PWCHAR
  52. InterpretFlagData(
  53. ULONG Flags
  54. )
  55. {
  56. static WCHAR buffer[1024] = { UNICODE_NULL };
  57. BOOL addComma = FALSE;
  58. DWORD i;
  59. for ( i = 0; i < sizeof(FlagData)/sizeof(FLAG_DATA); ++i ) {
  60. if ( FlagData[i].Flag & Flags ) {
  61. if ( addComma ) {
  62. wcscat( buffer, L", " );
  63. }
  64. wcscat( buffer, FlagData[i].Name );
  65. addComma = TRUE;
  66. }
  67. }
  68. return buffer;
  69. }
  70. int __cdecl
  71. wmain(
  72. int argc,
  73. WCHAR *argv[]
  74. )
  75. /*++
  76. Routine Description:
  77. main routine for utility
  78. Arguments:
  79. standard command line args
  80. Return Value:
  81. 0 if it worked successfully
  82. --*/
  83. {
  84. DWORD status;
  85. PDSROLE_PRIMARY_DOMAIN_INFO_BASIC domainInfo;
  86. status = DsRoleGetPrimaryDomainInformation(argv[1],
  87. DsRolePrimaryDomainInfoBasic,
  88. (PBYTE *)&domainInfo);
  89. printf("status = %u\n", status );
  90. printf("machine role = %ws\n"
  91. "flags = %08X (%ws)\n"
  92. "flat name = %ws\n"
  93. "dns name = %ws\n"
  94. "forest name = %ws\n",
  95. RoleNames[domainInfo->MachineRole],
  96. domainInfo->Flags, InterpretFlagData( domainInfo->Flags ),
  97. domainInfo->DomainNameFlat,
  98. domainInfo->DomainNameDns,
  99. domainInfo->DomainForestName);
  100. if ( domainInfo->Flags & DSROLE_PRIMARY_DOMAIN_GUID_PRESENT ) {
  101. WCHAR guidBuf[ 64 ];
  102. formatGuid( &domainInfo->DomainGuid, guidBuf );
  103. printf("domain Guid = %ws\n", guidBuf );
  104. }
  105. return 0;
  106. } // wmain
  107. /* end dsrole.c */