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.

168 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. ConfGetA.c
  5. Abstract:
  6. This module just contains NetpGetConfigTStrArray().
  7. Author:
  8. John Rogers (JohnRo) 08-May-1992
  9. Revision History:
  10. 08-May-1992 JohnRo
  11. Created.
  12. 08-May-1992 JohnRo
  13. Use <prefix.h> equates.
  14. 09-May-1992 JohnRo
  15. Handle max size zero (i.e. no keys at all with winreg APIs).
  16. 21-May-1992 JohnRo
  17. RAID 9826: Match revised winreg error codes.
  18. 05-Jun-1992 JohnRo
  19. Winreg title index parm is defunct.
  20. --*/
  21. // These must be included first:
  22. #include <nt.h> // NT definitions
  23. #include <ntrtl.h> // NT Rtl structures
  24. #include <nturtl.h> // NT Rtl structures
  25. #include <windows.h> // Needed by <configp.h> and <winreg.h>
  26. #include <lmcons.h> // LAN Manager common definitions
  27. #include <netdebug.h> // (Needed by config.h)
  28. // These may be included in any order:
  29. #include <config.h> // My prototype, LPNET_CONFIG_HANDLE.
  30. #include <configp.h> // USE_WIN32_CONFIG (if defined), etc.
  31. #include <debuglib.h> // IF_DEBUG()
  32. #include <lmerr.h> // LAN Manager network error definitions
  33. #include <netlib.h> // NetpMemoryAllocate(), etc.
  34. #include <netlibnt.h> // NetpAllocTStrFromString().
  35. #include <prefix.h> // PREFIX_ equates.
  36. #include <strarray.h> // LPTSTR_ARRAY, some TStr macros and funcs.
  37. #include <tstring.h> // NetpAllocWStrFromTStr(), TCHAR_EOS.
  38. // Return null-null array of strings.
  39. // Return NERR_CfgParamNotFound if the keyword isn't present.
  40. NET_API_STATUS
  41. NetpGetConfigTStrArray(
  42. IN LPNET_CONFIG_HANDLE ConfigHandle,
  43. IN LPTSTR Keyword,
  44. OUT LPTSTR_ARRAY * ValueBuffer // Must be freed by NetApiBufferFree().
  45. )
  46. /*++
  47. Routine Description:
  48. This function gets the keyword value string from the configuration file.
  49. Arguments:
  50. SectionPointer - Supplies the pointer to a specific section in the config
  51. file.
  52. Keyword - Supplies the string of the keyword within the specified
  53. section to look for.
  54. ValueBuffer - Returns the string of the keyword value which is
  55. copied into this buffer. This string will be allocated by this routine
  56. and must be freed by NetApiBufferFree().
  57. Return Value:
  58. NET_API_STATUS - NERR_Success or reason for failure.
  59. --*/
  60. {
  61. NET_API_STATUS ApiStatus;
  62. NET_CONFIG_HANDLE * MyHandle = ConfigHandle; // conv from opaque type
  63. LPTSTR_ARRAY ArrayStart;
  64. NetpAssert( ValueBuffer != NULL );
  65. *ValueBuffer = NULL; // assume error until proven otherwise.
  66. if ( (Keyword == NULL) || ((*Keyword) == TCHAR_EOS ) ) {
  67. return (ERROR_INVALID_PARAMETER);
  68. }
  69. {
  70. DWORD dwType;
  71. LONG Error;
  72. DWORD ValueSize;
  73. // Find out what max value length is.
  74. ApiStatus = NetpGetConfigMaxSizes (
  75. MyHandle,
  76. NULL, // Don't need max keyword size.
  77. & ValueSize); // Get max value length.
  78. if (ApiStatus != NO_ERROR) {
  79. NetpAssert( ApiStatus == NO_ERROR );
  80. return ApiStatus;
  81. }
  82. // If max size is zero (no entries), then skip out.
  83. if (ValueSize == 0) {
  84. return (NERR_CfgParamNotFound);
  85. }
  86. // Alloc space for the value.
  87. ArrayStart = NetpMemoryAllocate( ValueSize );
  88. if (ArrayStart == NULL) {
  89. return (ERROR_NOT_ENOUGH_MEMORY);
  90. }
  91. // Get the actual value.
  92. Error = RegQueryValueEx (
  93. MyHandle->WinRegKey,
  94. Keyword,
  95. NULL, // reserved
  96. & dwType,
  97. (LPVOID) ArrayStart, // out: value string (TCHARs).
  98. & ValueSize
  99. );
  100. IF_DEBUG(CONFIG) {
  101. NetpKdPrint(( PREFIX_NETLIB
  102. "NetpGetConfigTStrArray: RegQueryValueEx("
  103. FORMAT_LPTSTR ") returned " FORMAT_LONG ".\n",
  104. Keyword, Error ));
  105. }
  106. if (Error == ERROR_FILE_NOT_FOUND) {
  107. NetpMemoryFree( ArrayStart );
  108. return (NERR_CfgParamNotFound);
  109. } else if ( Error != ERROR_SUCCESS ) {
  110. NetpMemoryFree( ArrayStart );
  111. return (Error);
  112. } else if (dwType != REG_MULTI_SZ) {
  113. NetpMemoryFree( ArrayStart );
  114. IF_DEBUG(CONFIG) {
  115. NetpKdPrint(( PREFIX_NETLIB
  116. "NetpGetConfigTStrArray: got unexpected reg type "
  117. FORMAT_DWORD ".\n", dwType ));
  118. }
  119. return (ERROR_INVALID_DATA);
  120. }
  121. NetpAssert( ValueSize >= sizeof(TCHAR) );
  122. }
  123. NetpAssert( ArrayStart != NULL );
  124. IF_DEBUG(CONFIG) {
  125. NetpKdPrint(( PREFIX_NETLIB "NetpGetConfigTStrArray: value for '"
  126. FORMAT_LPTSTR "':\n", Keyword));
  127. NetpDisplayTStrArray( ArrayStart );
  128. }
  129. *ValueBuffer = ArrayStart;
  130. return NERR_Success;
  131. }