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.

190 lines
4.9 KiB

  1. /*++
  2. Copyright (c) 1992-1993 Microsoft Corporation
  3. Module Name:
  4. ConfMax.c
  5. Abstract:
  6. This module contains NetpGetConfigMaxSizes() and
  7. NetpGetWinRegConfigMaxSizes().
  8. Author:
  9. John Rogers (JohnRo) 13-Feb-1992
  10. Revision History:
  11. 13-Feb-1992 JohnRo
  12. Created.
  13. 06-Mar-1992 JohnRo
  14. Avoid compiler warnings in RTL and fake versions.
  15. 20-Mar-1992 JohnRo
  16. Update to DaveGi's proposed WinReg API changes.
  17. 07-May-1992 JohnRo
  18. Enable win32 registry for NET tree.
  19. 08-May-1992 JohnRo
  20. Use <prefix.h> equates.
  21. 09-May-1992 JohnRo
  22. Avoid assert when number of keys is zero.
  23. 05-Jun-1992 JohnRo
  24. Winreg title index parm is defunct.
  25. Handle RegQueryInfoKey bad return codes better.
  26. 13-Jun-1992 JohnRo
  27. Net config helpers should allow empty section.
  28. 08-Dec-1992 JohnRo
  29. RAID 4304: ReqQueryInfoKeyW returns sizes twice as big as actual.
  30. 19-Apr-1993 JohnRo
  31. RAID 5483: server manager: wrong path given in repl dialog.
  32. --*/
  33. // These must be included first:
  34. #include <nt.h> // NT definitions
  35. #include <ntrtl.h> // NT Rtl structures
  36. #include <nturtl.h> // NT Rtl structures
  37. #include <windows.h> // Needed by <configp.h> and <winreg.h>
  38. #include <lmcons.h> // LAN Manager common definitions
  39. // These may be included in any order:
  40. #include <configp.h> // NET_CONFIG_HANDLE
  41. #include <debuglib.h> // IF_DEBUG()
  42. #include <netdebug.h> // NetpKdPrint(()), etc.
  43. #include <netlib.h> // NetpSetOptionalArg().
  44. #include <prefix.h> // PREFIX_ equates.
  45. #include <winerror.h> // NO_ERROR.
  46. NET_API_STATUS
  47. NetpGetWinRegConfigMaxSizes (
  48. IN HKEY WinRegHandle,
  49. OUT LPDWORD MaxKeywordSize OPTIONAL,
  50. OUT LPDWORD MaxValueSize OPTIONAL
  51. )
  52. {
  53. LONG Error;
  54. TCHAR ClassName[ MAX_CLASS_NAME_LENGTH ];
  55. DWORD ClassNameLength;
  56. DWORD NumberOfSubKeys;
  57. DWORD MaxSubKeyLength;
  58. DWORD MaxClassLength;
  59. DWORD NumberOfValues;
  60. DWORD MaxValueNameLength;
  61. DWORD MaxValueDataLength;
  62. DWORD SecurityDescriptorSize;
  63. FILETIME LastWriteTime;
  64. ClassNameLength = MAX_CLASS_NAME_LENGTH;
  65. Error = RegQueryInfoKey(
  66. WinRegHandle,
  67. ClassName,
  68. &ClassNameLength,
  69. NULL, // reserved
  70. &NumberOfSubKeys,
  71. &MaxSubKeyLength,
  72. &MaxClassLength,
  73. &NumberOfValues,
  74. &MaxValueNameLength,
  75. &MaxValueDataLength,
  76. #ifndef REG_FILETIME
  77. &SecurityDescriptorSize,
  78. #endif
  79. &LastWriteTime
  80. );
  81. IF_DEBUG(CONFIG) {
  82. NetpKdPrint(( PREFIX_NETLIB
  83. "NetpGetWinRegConfigMaxSizes: RegQueryInfoKey returned "
  84. FORMAT_LONG ", key size " FORMAT_DWORD ", data size "
  85. FORMAT_DWORD ".\n",
  86. Error, MaxValueNameLength, MaxValueDataLength ));
  87. }
  88. if (Error != ERROR_SUCCESS) {
  89. NetpKdPrint(( PREFIX_NETLIB
  90. "NetpGetWinRegConfigMaxSizes: bad status " FORMAT_LONG
  91. " from RegQueryInfoKey, handle was " FORMAT_LPVOID
  92. ".\n", Error, WinRegHandle ));
  93. return ( (NET_API_STATUS) Error );
  94. }
  95. if (NumberOfValues > 0) {
  96. NetpAssert( MaxValueDataLength > 0 );
  97. NetpAssert( MaxValueNameLength > 0 );
  98. } else {
  99. // Handle empty section correctly too.
  100. NetpAssert( MaxValueDataLength == 0 );
  101. NetpAssert( MaxValueNameLength == 0 );
  102. }
  103. //
  104. // MaxValueNameLength is a count of TCHARs.
  105. // MaxValueDataLength is a count of bytes already.
  106. //
  107. MaxValueNameLength = (MaxValueNameLength + 1) * sizeof(TCHAR);
  108. NetpSetOptionalArg( MaxKeywordSize, MaxValueNameLength );
  109. NetpSetOptionalArg( MaxValueSize, MaxValueDataLength );
  110. return (NO_ERROR);
  111. } // NetpGetWinRegConfigMaxSizes
  112. NET_API_STATUS
  113. NetpGetConfigMaxSizes (
  114. IN NET_CONFIG_HANDLE * ConfigHandle,
  115. OUT LPDWORD MaxKeywordSize OPTIONAL,
  116. OUT LPDWORD MaxValueSize OPTIONAL
  117. )
  118. /*++
  119. Routine Description:
  120. Checks parameters and calls NetpGetWinRegConfigMaxSizes
  121. Arguments:
  122. Return Value:
  123. NET_API_STATUS - NO_ERROR or reason for failure.
  124. --*/
  125. {
  126. NET_CONFIG_HANDLE * lpnetHandle = ConfigHandle; // conv from opaque type
  127. NET_API_STATUS ApiStatus;
  128. //
  129. // Check for other invalid pointers, and make error handling code simpler.
  130. //
  131. if (MaxKeywordSize != NULL) {
  132. *MaxKeywordSize = 0;
  133. }
  134. if (MaxValueSize != NULL) {
  135. *MaxValueSize = 0;
  136. }
  137. //
  138. // Check for simple caller's errors.
  139. //
  140. if (ConfigHandle == NULL) {
  141. return (ERROR_INVALID_PARAMETER);
  142. }
  143. ApiStatus = NetpGetWinRegConfigMaxSizes(
  144. lpnetHandle->WinRegKey,
  145. MaxKeywordSize,
  146. MaxValueSize );
  147. return (ApiStatus);
  148. } // NetpGetConfigMaxSizes