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.

161 lines
4.5 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. ConfEnum.c
  5. Abstract:
  6. This file contains the RpcXlate code to handle the NetConfigGetAll API.
  7. Author:
  8. John Rogers (JohnRo) 24-Oct-1991
  9. Environment:
  10. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  11. Requires ANSI C extensions: slash-slash comments, long external names.
  12. Revision History:
  13. 24-Oct-1991 JohnRo
  14. Created.
  15. 01-Apr-1992 JohnRo
  16. Use NetApiBufferAllocate() instead of private version.
  17. 05-Jun-1992 JohnRo
  18. RAID 11253: NetConfigGetAll fails when remoted to downlevel.
  19. 01-Sep-1992 JohnRo
  20. RAID 5016: NetConfigGetAll heap trash.
  21. --*/
  22. // These must be included first:
  23. #include <windef.h> // IN, DWORD, etc.
  24. #include <lmcons.h> // DEVLEN, NET_API_STATUS, etc.
  25. // These may be included in any order:
  26. #include <apinums.h> // API_ equates.
  27. #include <lmapibuf.h> // NetApiBufferAllocate(), NetApiBufferFree().
  28. #include <lmerr.h> // ERROR_ and NERR_ equates.
  29. #include <lmconfig.h> // API's data structures.
  30. #include <netdebug.h> // NetpAssert().
  31. #include <rap.h> // LPDESC.
  32. #include <remdef.h> // REM16_, REM32_, REMSmb_ equates.
  33. #include <rx.h> // RxRemoteApi().
  34. #include <rxconfig.h> // My prototype(s).
  35. #include <strarray.h> // NetpCopyStrArrayToTStrArray.
  36. NET_API_STATUS
  37. RxNetConfigGetAll (
  38. IN LPTSTR UncServerName,
  39. IN LPTSTR Component,
  40. OUT LPBYTE *BufPtr
  41. )
  42. /*++
  43. Routine Description:
  44. RxNetConfigGetAll performs the same function as NetConfigGetAll,
  45. except that the server name is known to refer to a downlevel server.
  46. Arguments:
  47. (Same as NetConfigGetAll, except UncServerName must not be null, and
  48. must not refer to the local computer.)
  49. Return Value:
  50. (Same as NetConfigGetAll.)
  51. --*/
  52. {
  53. const DWORD BufSize = 65535;
  54. DWORD EntriesRead;
  55. NET_API_STATUS Status;
  56. DWORD TotalEntries;
  57. // Make sure caller didn't mess up.
  58. NetpAssert(UncServerName != NULL);
  59. if (BufPtr == NULL) {
  60. return (ERROR_INVALID_PARAMETER);
  61. }
  62. // Assume something might go wrong, and make error paths easier to
  63. // code. Also, check for bad pointers before we do anything.
  64. *BufPtr = NULL;
  65. //
  66. // Remote the API, which will allocate the array for us.
  67. //
  68. Status = RxRemoteApi(
  69. API_WConfigGetAll2, // api number
  70. UncServerName, // \\servername
  71. REMSmb_NetConfigGetAll_P, // parm desc (SMB version)
  72. REM16_configgetall_info,
  73. REM32_configgetall_info,
  74. REMSmb_configgetall_info,
  75. NULL, // no aux desc 16
  76. NULL, // no aux desc 32
  77. NULL, // no aux desc SMB
  78. ALLOCATE_RESPONSE, // flags: allocate buffer for us
  79. // rest of API's arguments in 32-bit LM 2.x format:
  80. NULL, // pszReserved
  81. Component, // pszComponent
  82. BufPtr, // Buffer: array (alloc for us)
  83. BufSize, // Buffer: array size in bytes
  84. & EntriesRead, // pcbEntriesRead
  85. & TotalEntries); // pcbTotalAvail
  86. NetpAssert( Status != ERROR_MORE_DATA );
  87. if (Status == NERR_Success) {
  88. #ifdef UNICODE
  89. DWORD SrcByteCount = NetpStrArraySize((LPSTR) *BufPtr);
  90. LPVOID TempBuff = *BufPtr; // non-UNICODE version of array.
  91. LPVOID UnicodeBuff;
  92. //
  93. // Allocate space for UNICODE version of array.
  94. //
  95. Status = NetApiBufferAllocate(
  96. SrcByteCount * sizeof(TCHAR),
  97. & UnicodeBuff);
  98. if (Status != NERR_Success) {
  99. return (Status);
  100. }
  101. NetpAssert(UnicodeBuff != NULL);
  102. //
  103. // Translate result array to Unicode.
  104. //
  105. NetpCopyStrArrayToTStrArray(
  106. UnicodeBuff, // dest (in UNICODE)
  107. TempBuff); // src array (in codepage)
  108. (void) NetApiBufferFree( TempBuff );
  109. *BufPtr = UnicodeBuff;
  110. #else // not UNICODE
  111. // BufPtr should already point at non-UNICODE array.
  112. NetpAssert( *BufPtr != NULL);
  113. #endif // not UNICODE
  114. } else {
  115. *BufPtr = NULL;
  116. }
  117. return (Status);
  118. } // RxNetConfigGetAll