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.

169 lines
4.2 KiB

  1. //
  2. // REGQKEY.C
  3. //
  4. // Copyright (C) Microsoft Corporation, 1995
  5. //
  6. // Implementation of RegQueryInfoKey.
  7. //
  8. #include "pch.h"
  9. //
  10. // VMMRegQueryInfoKey
  11. //
  12. // See Win32 documentation of RegQueryInfoKey. When VXD is defined, this
  13. // function does not take all of the parameters that we end up ignoring anyway
  14. // (class, security, timestamp parameters).
  15. //
  16. #ifdef VXD
  17. LONG
  18. REGAPI
  19. VMMRegQueryInfoKey(
  20. HKEY hKey,
  21. LPDWORD lpcSubKeys,
  22. LPDWORD lpcbMaxSubKeyLen,
  23. LPDWORD lpcValues,
  24. LPDWORD lpcbMaxValueName,
  25. LPDWORD lpcbMaxValueData
  26. )
  27. #else
  28. LONG
  29. REGAPI
  30. VMMRegQueryInfoKey(
  31. HKEY hKey,
  32. LPSTR lpClass,
  33. LPDWORD lpcbClass,
  34. LPDWORD lpReserved,
  35. LPDWORD lpcSubKeys,
  36. LPDWORD lpcbMaxSubKeyLen,
  37. LPDWORD lpcbMaxClassLen,
  38. LPDWORD lpcValues,
  39. LPDWORD lpcbMaxValueName,
  40. LPDWORD lpcbMaxValueData,
  41. LPVOID lpcbSecurityDescriptor,
  42. LPVOID lpftLastWriteTime
  43. )
  44. #endif
  45. {
  46. int ErrorCode;
  47. LPVALUE_RECORD lpValueRecord;
  48. UINT cItems;
  49. DWORD cbValueData;
  50. DWORD cbMaxValueData;
  51. DWORD cbStringLen;
  52. DWORD cbMaxStringLen;
  53. if (IsBadHugeOptionalWritePtr(lpcSubKeys, sizeof(DWORD)) ||
  54. IsBadHugeOptionalWritePtr(lpcbMaxSubKeyLen, sizeof(DWORD)) ||
  55. IsBadHugeOptionalWritePtr(lpcValues, sizeof(DWORD)) ||
  56. IsBadHugeOptionalWritePtr(lpcbMaxValueName, sizeof(DWORD)) ||
  57. IsBadHugeOptionalWritePtr(lpcbMaxValueData, sizeof(DWORD)))
  58. return ERROR_INVALID_PARAMETER;
  59. if (!RgLockRegistry())
  60. return ERROR_LOCK_FAILED;
  61. if ((ErrorCode = RgValidateAndConvertKeyHandle(&hKey)) != ERROR_SUCCESS)
  62. goto ReturnErrorCode;
  63. //
  64. // Compute cValues, cbMaxValueName, and cbMaxValueData.
  65. //
  66. if (!IsNullPtr(lpcValues) || !IsNullPtr(lpcbMaxValueName) ||
  67. !IsNullPtr(lpcbMaxValueData)) {
  68. cItems = 0;
  69. cbMaxStringLen = 0;
  70. cbMaxValueData = 0;
  71. while ((ErrorCode = RgLookupValueByIndex(hKey, cItems,
  72. &lpValueRecord)) == ERROR_SUCCESS) {
  73. cItems++;
  74. if (lpValueRecord-> NameLength > cbMaxStringLen)
  75. cbMaxStringLen = lpValueRecord-> NameLength;
  76. // RgCopyFromValueRecord will handle static and dynamic keys...
  77. ErrorCode = RgCopyFromValueRecord(hKey, lpValueRecord, NULL, NULL,
  78. NULL, NULL, &cbValueData);
  79. RgUnlockDatablock(hKey-> lpFileInfo, hKey-> BlockIndex, FALSE);
  80. if (ErrorCode != ERROR_SUCCESS)
  81. goto ReturnErrorCode;
  82. if (cbValueData > cbMaxValueData)
  83. cbMaxValueData = cbValueData;
  84. }
  85. if (ErrorCode == ERROR_NO_MORE_ITEMS) {
  86. if (!IsNullPtr(lpcValues))
  87. *lpcValues = cItems;
  88. if (!IsNullPtr(lpcbMaxValueName))
  89. *lpcbMaxValueName = cbMaxStringLen;
  90. if (!IsNullPtr(lpcbMaxValueData))
  91. *lpcbMaxValueData = cbMaxValueData;
  92. ErrorCode = ERROR_SUCCESS;
  93. }
  94. }
  95. //
  96. // Compute cSubKeys and cbMaxSubKeyLen. Somewhat painful because we must
  97. // touch each child keynode and datablock.
  98. //
  99. if (!IsNullPtr(lpcSubKeys) || !IsNullPtr(lpcbMaxSubKeyLen)) {
  100. cItems = 0;
  101. cbMaxStringLen = 0;
  102. while ((ErrorCode = RgLookupKeyByIndex(hKey, cItems, NULL,
  103. &cbStringLen)) == ERROR_SUCCESS) {
  104. cItems++;
  105. if (cbStringLen > cbMaxStringLen)
  106. cbMaxStringLen = cbStringLen;
  107. }
  108. if (ErrorCode == ERROR_NO_MORE_ITEMS) {
  109. if (!IsNullPtr(lpcSubKeys))
  110. *lpcSubKeys = cItems;
  111. if (!IsNullPtr(lpcbMaxSubKeyLen))
  112. *lpcbMaxSubKeyLen = cbMaxStringLen;
  113. ErrorCode = ERROR_SUCCESS;
  114. }
  115. }
  116. ReturnErrorCode:
  117. RgUnlockRegistry();
  118. return ErrorCode;
  119. #ifndef VXD
  120. UNREFERENCED_PARAMETER(lpClass);
  121. UNREFERENCED_PARAMETER(lpcbClass);
  122. UNREFERENCED_PARAMETER(lpReserved);
  123. UNREFERENCED_PARAMETER(lpcbMaxClassLen);
  124. UNREFERENCED_PARAMETER(lpcbSecurityDescriptor);
  125. UNREFERENCED_PARAMETER(lpftLastWriteTime);
  126. #endif
  127. }