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.

193 lines
6.0 KiB

  1. /*++
  2. Copyright (c) 1991-92 Microsoft Corporation
  3. Module Name:
  4. SvcGtInf.c
  5. Abstract:
  6. This file contains the RpcXlate code to handle the NetServiceGetInfo API.
  7. Author:
  8. John Rogers (JohnRo) 11-Sep-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. 11-Sep-1991 JohnRo
  14. Implement downlevel NetService APIs.
  15. 16-Sep-1991 JohnRo
  16. Fixed level check.
  17. 22-Oct-1991 JohnRo
  18. Free buffer on error.
  19. 07-Feb-1992 JohnRo
  20. Use NetApiBufferAllocate() instead of private version.
  21. --*/
  22. // These must be included first:
  23. #include <windef.h> // IN, DWORD, etc.
  24. #include <lmcons.h> // LM20_ equates, NET_API_STATUS, etc.
  25. // These may be included in any order:
  26. #include <apinums.h> // API_ equates.
  27. #include <lmapibuf.h> // NetApiBufferAllocate().
  28. #include <lmerr.h> // ERROR_ and NERR_ equates.
  29. #include <lmsvc.h>
  30. #include <rxp.h> // RxpFatalErrorCode().
  31. #include <netdebug.h> // DBGSTATIC, NetpKdPrint(()), FORMAT_ equates.
  32. #include <rap.h> // LPDESC.
  33. #include <remdef.h> // REM16_, REM32_, REMSmb_ equates.
  34. #include <rx.h> // RxRemoteApi().
  35. #include <rxpdebug.h> // IF_DEBUG().
  36. #include <rxsvc.h> // My prototype.
  37. #include <strucinf.h> // NetpServiceStructureInfo().
  38. NET_API_STATUS
  39. RxNetServiceGetInfo (
  40. IN LPTSTR UncServerName,
  41. IN LPTSTR Service,
  42. IN DWORD Level,
  43. OUT LPBYTE *BufPtr
  44. )
  45. /*++
  46. Routine Description:
  47. RxNetServiceGetInfo performs the same function as NetServiceGetInfo, except
  48. that the server name is known to refer to a downlevel server.
  49. Arguments:
  50. (Same as NetServiceGetInfo, except UncServerName must not be null, and
  51. must not refer to the local computer.)
  52. Return Value:
  53. (Same as NetServiceGetInfo.)
  54. --*/
  55. {
  56. LPDESC DataDesc16, DataDesc32, DataDescSmb;
  57. LPBYTE ApiBuffer32; // Buffer to be returned to caller.
  58. DWORD ApiBufferSize32;
  59. NET_API_STATUS Status;
  60. DWORD TotalAvail;
  61. LPSERVICE_INFO_2 serviceInfo2;
  62. IF_DEBUG(SERVICE) {
  63. NetpKdPrint(("RxNetServiceGetInfo: starting, server=" FORMAT_LPTSTR
  64. ", lvl=" FORMAT_DWORD ".\n", UncServerName, Level));
  65. }
  66. //
  67. // Error check DLL stub and the app.
  68. //
  69. NetpAssert(UncServerName != NULL);
  70. if (BufPtr == NULL) {
  71. return (ERROR_INVALID_PARAMETER);
  72. }
  73. *BufPtr = NULL; // assume error; it makes error handlers easy to code.
  74. // This also forces possible GP fault before we allocate memory.
  75. //
  76. // Learn about info level.
  77. //
  78. Status = NetpServiceStructureInfo (
  79. Level, // level to learn about
  80. PARMNUM_ALL, // No parmnum with this.
  81. TRUE, // Need native sizes.
  82. & DataDesc16,
  83. & DataDesc32,
  84. & DataDescSmb,
  85. & ApiBufferSize32, // max buffer size (native)
  86. NULL, // don't need fixed size.
  87. NULL // don't need string size.
  88. );
  89. if (Status != NERR_Success) {
  90. return (Status);
  91. }
  92. //
  93. // Allocate memory for 32-bit version of info, which we'll use to get
  94. // data from the remote computer.
  95. //
  96. Status = NetApiBufferAllocate(
  97. ApiBufferSize32,
  98. (LPVOID *) & ApiBuffer32);
  99. if (Status != NERR_Success) {
  100. return (Status);
  101. }
  102. IF_DEBUG(SERVICE) {
  103. NetpKdPrint(( "RxNetServiceGetInfo: allocated buffer at "
  104. FORMAT_LPVOID "\n", (LPVOID) ApiBuffer32 ));
  105. }
  106. //
  107. // Actually remote the API, which will get back the
  108. // data in native format.
  109. //
  110. Status = RxRemoteApi(
  111. API_WServiceGetInfo, // API number
  112. UncServerName, // Required, with \\name.
  113. REMSmb_NetServiceGetInfo_P, // parm desc
  114. DataDesc16,
  115. DataDesc32,
  116. DataDescSmb,
  117. NULL, // no aux data desc 16
  118. NULL, // no aux data desc 32
  119. NULL, // no aux data desc SMB
  120. FALSE, // not a null session API
  121. // rest of API's arguments, in 32-bit LM 2.x format:
  122. Service,
  123. Level,
  124. ApiBuffer32,
  125. ApiBufferSize32,
  126. & TotalAvail); // total size
  127. NetpAssert( Status != ERROR_MORE_DATA );
  128. NetpAssert( Status != NERR_BufTooSmall );
  129. if (Status == NERR_Success) {
  130. *BufPtr = ApiBuffer32;
  131. if ((! RxpFatalErrorCode(Status)) && ((Level == 2) || (Level==1 ))) {
  132. serviceInfo2 = (LPSERVICE_INFO_2)*BufPtr;
  133. if (serviceInfo2 != NULL) {
  134. DWORD installState;
  135. if (Level == 2) {
  136. serviceInfo2->svci2_display_name = serviceInfo2->svci2_name;
  137. }
  138. //
  139. // if INSTALL or UNINSTALL is PENDING, then force the upper
  140. // bits to 0. This is to prevent the upper bits of the wait
  141. // hint from getting accidentally set. Downlevel should never
  142. // use more than FF for waithint.
  143. //
  144. installState = serviceInfo2->svci2_status & SERVICE_INSTALL_STATE;
  145. if ((installState == SERVICE_INSTALL_PENDING) ||
  146. (installState == SERVICE_UNINSTALL_PENDING)) {
  147. serviceInfo2->svci2_code &= SERVICE_RESRV_MASK;
  148. }
  149. }
  150. }
  151. } else {
  152. (void) NetApiBufferFree( ApiBuffer32 );
  153. }
  154. return (Status);
  155. } // RxNetServiceGetInfo