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.

390 lines
7.4 KiB

  1. /*++
  2. DMPSTATE.CXX
  3. Copyright (C) 1999 Microsoft Corporation, all rights reserved.
  4. DESCRIPTION: code and support for DumpState()
  5. Created, May 21, 1999 by DavidCHR.
  6. --*/
  7. #include "everything.hxx"
  8. extern NTSTATUS // realmflags.cxx
  9. GetRealmFlags( IN LPWSTR RealmName,
  10. OUT PULONG pulRealmFlags );
  11. extern VOID // realmflags.cxx
  12. PrintRealmFlags( IN ULONG RealmFlags );
  13. DWORD
  14. LoadAndPrintNames( IN LPSTR KeyName,
  15. IN HKEY DomainKey,
  16. IN BOOL bPrintEmptyIfMissing,
  17. IN LPWSTR ValueName ) {
  18. ULONG KdcNameSize = 0, i;
  19. LPWSTR KdcNames;
  20. DWORD WinError = STATUS_UNSUCCESSFUL;
  21. DWORD Type;
  22. CMULTISTRING StringClass;
  23. if ( StringClass.ReadFromRegistry( DomainKey,
  24. ValueName ) ) {
  25. if ( StringClass.cEntries != 0 ) {
  26. for ( i = 0 ;
  27. i < StringClass.cEntries ;
  28. i ++ ) {
  29. printf( "\t%hs = %ws\n",
  30. KeyName,
  31. StringClass.pEntries[ i ] );
  32. }
  33. } else {
  34. if ( bPrintEmptyIfMissing ) {
  35. printf( "\t(no %hs entries for this realm)\n",
  36. KeyName );
  37. }
  38. }
  39. }
  40. return WinError;
  41. }
  42. NTSTATUS
  43. PrintRealmList( VOID ) {
  44. NTSTATUS Status = STATUS_SUCCESS;
  45. ULONG WinError;
  46. HKEY DomainRootKey = NULL;
  47. HKEY DomainKey = NULL;
  48. LPWSTR KdcNames = NULL;
  49. LPWSTR AlternateRealmNames = NULL;
  50. TCHAR DomainName[128]; // max domain name length
  51. ULONG Index,Index2;
  52. ULONG Type;
  53. ULONG NameSize;
  54. ULONG KdcNameSize = 0;
  55. ULONG AltRealmSize = 0;
  56. LPWSTR Where;
  57. ULONG NameCount;
  58. UNICODE_STRING TempString;
  59. ULONG RealmFlags;
  60. //
  61. // Open the domains root key - if it is not there, so be it.
  62. //
  63. WinError = RegOpenKey(
  64. HKEY_LOCAL_MACHINE,
  65. KERB_DOMAINS_KEY,
  66. &DomainRootKey
  67. );
  68. switch( WinError ) {
  69. case ERROR_FILE_NOT_FOUND:
  70. printf( "(No RFC1510 Kerberos Realms are defined).\n" );
  71. goto Cleanup;
  72. case ERROR_SUCCESS:
  73. break;
  74. default:
  75. printf("Failed to open key %ws: 0x%x\n", KERB_DOMAINS_KEY, WinError );
  76. goto Cleanup;
  77. }
  78. //
  79. // If it is there, we now want to enumerate all the child keys.
  80. //
  81. Index = 0;
  82. for (Index = 0; TRUE ; Index++ )
  83. {
  84. //
  85. // Enumerate through all the keys
  86. //
  87. NameSize = sizeof(DomainName) / sizeof( DomainName[ 0 ] );
  88. WinError = RegEnumKeyEx(
  89. DomainRootKey,
  90. Index,
  91. DomainName,
  92. &NameSize,
  93. NULL,
  94. NULL,
  95. NULL,
  96. NULL
  97. );
  98. if (WinError != ERROR_SUCCESS)
  99. {
  100. if ( WinError != ERROR_NO_MORE_ITEMS ) {
  101. printf( "Registry error 0x%x while enumerating domains. Stopping here.\n",
  102. WinError );
  103. }
  104. break;
  105. }
  106. //
  107. // Open the domain key to tread the values under it
  108. //
  109. WinError = RegOpenKey(
  110. DomainRootKey,
  111. DomainName,
  112. &DomainKey
  113. );
  114. if (WinError != ERROR_SUCCESS)
  115. {
  116. printf("Failed to open key %ws \\ %ws: 0x%x\n",
  117. KERB_DOMAINS_KEY, DomainName, WinError );
  118. break;
  119. }
  120. printf( "%ws:\n",
  121. DomainName );
  122. LoadAndPrintNames( "kdc",
  123. DomainKey,
  124. TRUE,
  125. KERB_DOMAIN_KDC_NAMES_VALUE );
  126. LoadAndPrintNames( "AlternateRealmName",
  127. DomainKey,
  128. FALSE,
  129. KERB_DOMAIN_ALT_NAMES_VALUE );
  130. LoadAndPrintNames( "kpasswd",
  131. DomainKey,
  132. FALSE,
  133. KERB_DOMAIN_KPASSWD_NAMES_VALUE );
  134. if ( NT_SUCCESS( GetRealmFlags( DomainName,
  135. &RealmFlags ) ) ) {
  136. printf( "\tRealm Flags = 0x%x",
  137. RealmFlags );
  138. PrintRealmFlags( RealmFlags );
  139. printf( "\n" );
  140. }
  141. }
  142. Cleanup:
  143. if (KdcNames != NULL)
  144. {
  145. LocalFree(KdcNames);
  146. }
  147. if (AlternateRealmNames != NULL)
  148. {
  149. LocalFree(AlternateRealmNames);
  150. }
  151. return(Status);
  152. }
  153. NTSTATUS
  154. PrintNameMapping( VOID )
  155. {
  156. DWORD RegErr;
  157. HKEY KerbHandle = NULL;
  158. HKEY UserListHandle = NULL;
  159. WCHAR ValueNameBuffer[500];
  160. WCHAR ValueDataBuffer[500];
  161. PWSTR ValueName;
  162. PWSTR ValueData;
  163. ULONG NameLength;
  164. ULONG DataLength;
  165. ULONG Index;
  166. ULONG Type;
  167. BOOL FoundAnyMappings = FALSE;
  168. CMULTISTRING StringClass;
  169. RegErr = OpenKerberosKey(&KerbHandle);
  170. if (RegErr)
  171. {
  172. goto Cleanup;
  173. }
  174. RegErr = RegOpenKeyEx(
  175. KerbHandle,
  176. L"UserList",
  177. 0, // no options
  178. KEY_QUERY_VALUE,
  179. &UserListHandle
  180. );
  181. switch( RegErr ) {
  182. case ERROR_FILE_NOT_FOUND:
  183. goto NoMappingsWereFound;
  184. case ERROR_SUCCESS:
  185. break; // success condition.
  186. default:
  187. printf("Failed to create UserList key: 0x%x\n",RegErr);
  188. goto Cleanup;
  189. }
  190. for ( Index = 0;
  191. ; // forever
  192. Index++ ) {
  193. NameLength = sizeof(ValueNameBuffer);
  194. DataLength = sizeof(ValueDataBuffer);
  195. ValueName = ValueNameBuffer;
  196. ValueData = ValueDataBuffer;
  197. RtlZeroMemory(
  198. ValueName,
  199. NameLength
  200. );
  201. RtlZeroMemory(
  202. ValueData,
  203. DataLength
  204. );
  205. // 279626: this value should be in bytes
  206. NameLength /= sizeof( WCHAR );
  207. RegErr = RegEnumValue( UserListHandle,
  208. Index,
  209. ValueName,
  210. &NameLength,
  211. NULL,
  212. &Type,
  213. (PBYTE) ValueData,
  214. &DataLength
  215. );
  216. if ( RegErr == ERROR_SUCCESS ) {
  217. if ( _wcsicmp( ValueName , L"*" ) == 0 ) {
  218. ValueName = L"all users (*)";
  219. }
  220. if (_wcsicmp(ValueData,L"*") == 0) {
  221. ValueData = L"a local account by the same name (*)";
  222. }
  223. FoundAnyMappings = TRUE;
  224. printf( "Mapping %ws to %ws.\n",
  225. ValueName,
  226. ValueData );
  227. } else {
  228. if ( RegErr != ERROR_NO_MORE_ITEMS ) {
  229. printf( "Registry error 0x%x while enumerating user mappings. Stopping here.\n",
  230. RegErr );
  231. }
  232. break;
  233. }
  234. }
  235. if ( !FoundAnyMappings ) {
  236. NoMappingsWereFound:
  237. printf( "No user mappings defined.\n" );
  238. }
  239. Cleanup:
  240. if (KerbHandle)
  241. {
  242. RegCloseKey(KerbHandle);
  243. }
  244. if (UserListHandle)
  245. {
  246. RegCloseKey(UserListHandle);
  247. }
  248. return(STATUS_SUCCESS);
  249. }
  250. NTSTATUS
  251. DumpState(LPWSTR * Parameters)
  252. {
  253. NTSTATUS Status;
  254. PPOLICY_DNS_DOMAIN_INFO DnsDomainInfo = NULL;
  255. Status = LsaQueryInformationPolicy(
  256. LsaHandle,
  257. PolicyDnsDomainInformation,
  258. (PVOID *) &DnsDomainInfo
  259. );
  260. if (!NT_SUCCESS(Status))
  261. {
  262. printf("Failed to query dns domain info: 0x%x\n",Status);
  263. goto Cleanup;
  264. }
  265. if ( DnsDomainInfo->DnsDomainName.Length == 0 ) {
  266. printf("Machine is not configured to log on to an external KDC. Probably a workgroup member\n");
  267. /* goto Cleanup;
  268. 101055: Don't do this-- not having joined the domain doesn't
  269. preclude us from having KDC entries defined. */
  270. } else { // nonempty dns domain, but no sid. Assume we're in an RFC1510 domain.
  271. printf( "default realm = %wZ ",
  272. &DnsDomainInfo->DnsDomainName );
  273. if ( DnsDomainInfo->Sid != NULL ) {
  274. printf( "(NT Domain)\n" );
  275. } else {
  276. printf( "(external)\n" );
  277. }
  278. }
  279. PrintRealmList();
  280. PrintNameMapping();
  281. Cleanup:
  282. if (DnsDomainInfo != NULL)
  283. {
  284. LsaFreeMemory(DnsDomainInfo);
  285. }
  286. return(Status);
  287. }