/*++ Copyright (c) 1992 Microsoft Corporation Module Name: ConfGetA.c Abstract: This module just contains NetpGetConfigTStrArray(). Author: John Rogers (JohnRo) 08-May-1992 Revision History: 08-May-1992 JohnRo Created. 08-May-1992 JohnRo Use equates. 09-May-1992 JohnRo Handle max size zero (i.e. no keys at all with winreg APIs). 21-May-1992 JohnRo RAID 9826: Match revised winreg error codes. 05-Jun-1992 JohnRo Winreg title index parm is defunct. --*/ // These must be included first: #include // NT definitions #include // NT Rtl structures #include // NT Rtl structures #include // Needed by and #include // LAN Manager common definitions #include // (Needed by config.h) // These may be included in any order: #include // My prototype, LPNET_CONFIG_HANDLE. #include // USE_WIN32_CONFIG (if defined), etc. #include // IF_DEBUG() #include // LAN Manager network error definitions #include // NetpMemoryAllocate(), etc. #include // NetpAllocTStrFromString(). #include // PREFIX_ equates. #include // LPTSTR_ARRAY, some TStr macros and funcs. #include // NetpAllocWStrFromTStr(), TCHAR_EOS. // Return null-null array of strings. // Return NERR_CfgParamNotFound if the keyword isn't present. NET_API_STATUS NetpGetConfigTStrArray( IN LPNET_CONFIG_HANDLE ConfigHandle, IN LPTSTR Keyword, OUT LPTSTR_ARRAY * ValueBuffer // Must be freed by NetApiBufferFree(). ) /*++ Routine Description: This function gets the keyword value string from the configuration file. Arguments: SectionPointer - Supplies the pointer to a specific section in the config file. Keyword - Supplies the string of the keyword within the specified section to look for. ValueBuffer - Returns the string of the keyword value which is copied into this buffer. This string will be allocated by this routine and must be freed by NetApiBufferFree(). Return Value: NET_API_STATUS - NERR_Success or reason for failure. --*/ { NET_API_STATUS ApiStatus; NET_CONFIG_HANDLE * MyHandle = ConfigHandle; // conv from opaque type LPTSTR_ARRAY ArrayStart; NetpAssert( ValueBuffer != NULL ); *ValueBuffer = NULL; // assume error until proven otherwise. if ( (Keyword == NULL) || ((*Keyword) == TCHAR_EOS ) ) { return (ERROR_INVALID_PARAMETER); } #if defined(USE_WIN32_CONFIG) { DWORD dwType; LONG Error; DWORD ValueSize; // Find out what max value length is. ApiStatus = NetpGetConfigMaxSizes ( MyHandle, NULL, // Don't need max keyword size. & ValueSize); // Get max value length. NetpAssert( ApiStatus == NO_ERROR ); // BUGBUG // If max size is zero (no entries), then skip out. if (ValueSize == 0) { return (NERR_CfgParamNotFound); } // Alloc space for the value. ArrayStart = NetpMemoryAllocate( ValueSize ); if (ArrayStart == NULL) { return (ERROR_NOT_ENOUGH_MEMORY); } // Get the actual value. Error = RegQueryValueEx ( MyHandle->WinRegKey, Keyword, NULL, // reserved & dwType, (LPVOID) ArrayStart, // out: value string (TCHARs). & ValueSize ); IF_DEBUG(CONFIG) { NetpKdPrint(( PREFIX_NETLIB "NetpGetConfigTStrArray: RegQueryValueEx(" FORMAT_LPTSTR ") returned " FORMAT_LONG ".\n", Keyword, Error )); } if (Error == ERROR_FILE_NOT_FOUND) { NetpMemoryFree( ArrayStart ); return (NERR_CfgParamNotFound); } else if ( Error != ERROR_SUCCESS ) { NetpMemoryFree( ArrayStart ); return (Error); } else if (dwType != REG_MULTI_SZ) { NetpMemoryFree( ArrayStart ); IF_DEBUG(CONFIG) { NetpKdPrint(( PREFIX_NETLIB "NetpGetConfigTStrArray: got unexpected reg type " FORMAT_DWORD ".\n", dwType )); } return (ERROR_INVALID_DATA); } NetpAssert( ValueSize >= sizeof(TCHAR) ); } NetpAssert( ArrayStart != NULL ); // BUGBUG: realloc array to shrink it. IF_DEBUG(CONFIG) { NetpKdPrint(( PREFIX_NETLIB "NetpGetConfigTStrArray: value for '" FORMAT_LPTSTR "':\n", Keyword)); NetpDisplayTStrArray( ArrayStart ); } *ValueBuffer = ArrayStart; return NERR_Success; #elif defined(FAKE_PER_PROCESS_RW_CONFIG) return (ERROR_NOT_SUPPORTED); #else // NT RTL read-only temporary stuff return (ERROR_NOT_SUPPORTED); #endif // NT RTL read-only temporary stuff /*NOTREACHED*/ }