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.

175 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. ConfGet.c
  5. Abstract:
  6. This file contains the RpcXlate code to handle the NetConfigGet 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. 28-Oct-1991 JohnRo
  16. Made changes suggested by PC-LINT. (Only affects UNICODE option.)
  17. 01-Apr-1992 JohnRo
  18. Use NetApiBufferAllocate() instead of private version.
  19. 05-Jun-1992 JohnRo
  20. RAID 11253: NetConfigGetAll fails when remoted to downlevel.
  21. Use PREFIX_ equates.
  22. 23-Oct-1992 JohnRo
  23. RAID 9357: server mgr: can't add to alerts list on downlevel.
  24. Fixed __stdcall for RpcXlate workers.
  25. --*/
  26. // These must be included first:
  27. #include <windef.h> // IN, DWORD, etc.
  28. #include <lmcons.h> // LM20_ equates, NET_API_STATUS, etc.
  29. // These may be included in any order:
  30. #include <apinums.h> // API_ equates.
  31. #include <lmapibuf.h> // NetApiBufferAllocate(), NetApiBufferFree().
  32. #include <lmerr.h> // ERROR_ and NERR_ equates.
  33. #include <netdebug.h> // NetpKdPrint(()), FORMAT_ equates, etc.
  34. #include <prefix.h> // PREFIX_ equates.
  35. #include <rap.h> // LPDESC.
  36. #include <remdef.h> // REM16_, REM32_, REMSmb_ equates.
  37. #include <rx.h> // RxRemoteApi().
  38. #include <rxpdebug.h> // IF_DEBUG().
  39. #include <rxconfig.h> // My prototype.
  40. #include <tstring.h> // NetpCopyStrToTStr().
  41. NET_API_STATUS
  42. RxNetConfigGet (
  43. IN LPTSTR UncServerName,
  44. IN LPTSTR Component,
  45. IN LPTSTR Parameter,
  46. OUT LPBYTE *BufPtr
  47. )
  48. /*++
  49. Routine Description:
  50. RxNetConfigGet performs the same function as NetConfigGet,
  51. except that the server name is known to refer to a downlevel server.
  52. Arguments:
  53. (Same as NetConfigGet, except UncServerName must not be null, and
  54. must not refer to the local computer.)
  55. Return Value:
  56. (Same as NetConfigGet.)
  57. --*/
  58. {
  59. const DWORD BufSize = 65535;
  60. NET_API_STATUS Status;
  61. DWORD TotalAvail;
  62. IF_DEBUG(CONFIG) {
  63. NetpKdPrint(( PREFIX_NETAPI "RxNetConfigGet: starting, server="
  64. FORMAT_LPTSTR
  65. ", component=" FORMAT_LPTSTR ", parm=" FORMAT_LPTSTR ".\n",
  66. UncServerName, Component, Parameter ));
  67. }
  68. //
  69. // Error check DLL stub and the app.
  70. //
  71. NetpAssert(UncServerName != NULL);
  72. if (BufPtr == NULL) {
  73. return (ERROR_INVALID_PARAMETER);
  74. }
  75. *BufPtr = NULL; // assume error; it makes error handlers easy to code.
  76. // This also forces possible GP fault before we allocate memory.
  77. //
  78. // Actually remote the API, which will get back the
  79. // data in native format.
  80. //
  81. Status = RxRemoteApi(
  82. API_WConfigGet2, // API number
  83. UncServerName, // Required, with \\name.
  84. REMSmb_NetConfigGet_P, // parm desc
  85. REM16_configget_info, // data desc 16
  86. REM32_configget_info, // data desc 32
  87. REMSmb_configget_info, // data desc SMB
  88. NULL, // no aux data desc 16
  89. NULL, // no aux data desc 32
  90. NULL, // no aux data desc SMB
  91. ALLOCATE_RESPONSE, // Flags: alloc mem for us.
  92. // rest of API's arguments, in 32-bit LM 2.x format:
  93. NULL, // reserved (must be null pointer)
  94. Component,
  95. Parameter,
  96. BufPtr, // pbBuffer (will be set)
  97. BufSize, // cbBuffer
  98. & TotalAvail); // total size (meaningless!)
  99. NetpAssert( Status != ERROR_MORE_DATA );
  100. NetpAssert( Status != NERR_BufTooSmall );
  101. if (Status == NERR_Success) {
  102. #ifdef UNICODE
  103. DWORD SrcByteCount = strlen((LPSTR) *BufPtr)+1; // Bytes for 8-bit str.
  104. LPVOID TempBuff = *BufPtr; // non-UNICODE version of string.
  105. LPVOID UnicodeBuff;
  106. //
  107. // Allocate space for UNICODE version of string.
  108. //
  109. Status = NetApiBufferAllocate(
  110. SrcByteCount * sizeof(TCHAR),
  111. & UnicodeBuff);
  112. if (Status != NERR_Success) {
  113. return (Status);
  114. }
  115. NetpAssert(UnicodeBuff != NULL);
  116. //
  117. // Translate result string to Unicode.
  118. //
  119. NetpCopyStrToTStr(
  120. UnicodeBuff, // dest (in UNICODE)
  121. TempBuff); // src string (in codepage)
  122. (void) NetApiBufferFree( TempBuff );
  123. *BufPtr = UnicodeBuff;
  124. #else // not UNICODE
  125. // BufPtr should already point at non-UNICODE string.
  126. NetpAssert( *BufPtr != NULL);
  127. #endif // not UNICODE
  128. } else {
  129. *BufPtr = NULL;
  130. }
  131. return (Status);
  132. } // RxNetConfigGet