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.

215 lines
5.2 KiB

  1. //=================================================================
  2. //
  3. // MprAPI.cpp
  4. //
  5. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #include <nt.h>
  9. #include <ntrtl.h>
  10. #include <nturtl.h>
  11. #include <ntobapi.h>
  12. #define _WINNT_ // have what is needed from above
  13. #include "precomp.h"
  14. #include <cominit.h>
  15. #include <lmuse.h>
  16. #include "DllWrapperBase.h"
  17. #include "MprApi.h"
  18. #include "DllWrapperCreatorReg.h"
  19. // {EA6034F1-0FAD-11d3-910C-00105AA630BE}
  20. static const GUID g_guidMprApi =
  21. { 0xea6034f1, 0xfad, 0x11d3, { 0x91, 0xc, 0x0, 0x10, 0x5a, 0xa6, 0x30, 0xbe } };
  22. static const TCHAR g_tstrMpr [] = _T("Mpr.Dll");
  23. /******************************************************************************
  24. * Register this class with the CResourceManager.
  25. *****************************************************************************/
  26. CDllApiWraprCreatrReg<CMprApi, &g_guidMprApi, g_tstrMpr> MyRegisteredMprWrapper;
  27. /******************************************************************************
  28. * Constructor
  29. *****************************************************************************/
  30. CMprApi::CMprApi(LPCTSTR a_tstrWrappedDllName)
  31. : CDllWrapperBase(a_tstrWrappedDllName),
  32. m_pfnWNetEnumResource (NULL),
  33. m_pfnWNetOpenEnum(NULL),
  34. m_pfnWNetCloseEnum(NULL),
  35. m_pfnWNetGetUser(NULL),
  36. m_pfnWNetGetConnection(NULL)
  37. {
  38. }
  39. /******************************************************************************
  40. * Destructor
  41. *****************************************************************************/
  42. CMprApi::~CMprApi()
  43. {
  44. }
  45. /******************************************************************************
  46. * Initialization function to check that we obtained function addresses.
  47. ******************************************************************************/
  48. bool CMprApi::Init()
  49. {
  50. bool fRet = LoadLibrary();
  51. if(fRet)
  52. {
  53. #ifdef UNICODE
  54. m_pfnWNetGetUser = ( PFN_Mpr_WNetGetUser ) GetProcAddress ( "WNetGetUserW" ) ;
  55. m_pfnWNetEnumResource = ( PFN_Mpr_WNetEnumResource ) GetProcAddress ( "WNetEnumResourceW" ) ;
  56. m_pfnWNetOpenEnum = ( PFN_Mpr_WNetOpenEnum ) GetProcAddress ( "WNetOpenEnumW" ) ;
  57. m_pfnWNetGetConnection = ( PFN_Mpr_WNetGetConnection ) GetProcAddress ( "WNetGetConnectionW" ) ;
  58. #else
  59. m_pfnWNetGetUser = ( PFN_Mpr_WNetGetUser ) GetProcAddress ( "WNetGetUserA" ) ;
  60. m_pfnWNetEnumResource = ( PFN_Mpr_WNetEnumResource ) GetProcAddress ( "WNetEnumResourceA" ) ;
  61. m_pfnWNetOpenEnum = ( PFN_Mpr_WNetOpenEnum ) GetProcAddress ( "WNetOpenEnumA" ) ;
  62. m_pfnWNetGetConnection = ( PFN_Mpr_WNetGetConnection ) GetProcAddress ( "WNetGetConnectionA" ) ;
  63. #endif
  64. m_pfnWNetCloseEnum = ( PFN_Mpr_WNetCloseEnum ) GetProcAddress ( "WNetCloseEnum" ) ;
  65. }
  66. // We require these function for all versions of this dll.
  67. if ( m_pfnWNetEnumResource == NULL ||
  68. m_pfnWNetOpenEnum == NULL ||
  69. m_pfnWNetCloseEnum == NULL ||
  70. m_pfnWNetGetUser == NULL )
  71. {
  72. fRet = false;
  73. LogErrorMessage(L"Failed find entrypoint in MPRAPI");
  74. }
  75. return fRet;
  76. }
  77. /******************************************************************************
  78. * Member functions wrapping Tapi api functions. Add new functions here
  79. * as required.
  80. *****************************************************************************/
  81. #ifdef UNICODE
  82. DWORD CMprApi :: WNetEnumResource (
  83. IN HANDLE hEnum,
  84. IN OUT LPDWORD lpcCount,
  85. OUT LPVOID lpBuffer,
  86. IN OUT LPDWORD lpBufferSize
  87. )
  88. #else
  89. DWORD CMprApi :: WNetEnumResource (
  90. IN HANDLE hEnum,
  91. IN OUT LPDWORD lpcCount,
  92. OUT LPVOID lpBuffer,
  93. IN OUT LPDWORD lpBufferSize
  94. )
  95. #endif
  96. {
  97. return m_pfnWNetEnumResource (
  98. hEnum,
  99. lpcCount,
  100. lpBuffer,
  101. lpBufferSize
  102. ) ;
  103. }
  104. #ifdef UNICODE
  105. DWORD CMprApi :: WNetOpenEnum (
  106. IN DWORD dwScope,
  107. IN DWORD dwType,
  108. IN DWORD dwUsage,
  109. IN LPNETRESOURCEW lpNetResource,
  110. OUT LPHANDLE lphEnum
  111. )
  112. #else
  113. DWORD CMprApi :: WNetOpenEnum (
  114. IN DWORD dwScope,
  115. IN DWORD dwType,
  116. IN DWORD dwUsage,
  117. IN LPNETRESOURCEA lpNetResource,
  118. OUT LPHANDLE lphEnum
  119. )
  120. #endif
  121. {
  122. return m_pfnWNetOpenEnum (
  123. dwScope,
  124. dwType,
  125. dwUsage,
  126. lpNetResource,
  127. lphEnum
  128. ) ;
  129. }
  130. #ifdef UNICODE
  131. DWORD CMprApi :: WNetGetUser (
  132. IN LPCWSTR lpName,
  133. OUT LPWSTR lpUserName,
  134. IN OUT LPDWORD lpnLength
  135. )
  136. #else
  137. DWORD CMprApi :: WNetGetUser (
  138. IN LPCSTR lpName,
  139. OUT LPSTR lpUserName,
  140. IN OUT LPDWORD lpnLength
  141. )
  142. #endif
  143. {
  144. return m_pfnWNetGetUser (
  145. lpName,
  146. lpUserName,
  147. lpnLength
  148. ) ;
  149. }
  150. DWORD CMprApi :: WNetCloseEnum (
  151. IN HANDLE hEnum
  152. )
  153. {
  154. return m_pfnWNetCloseEnum (
  155. hEnum
  156. ) ;
  157. }
  158. #ifdef UNICODE
  159. DWORD CMprApi :: WNetGetConnection (
  160. IN LPCWSTR lpLocalName,
  161. OUT LPWSTR lpRemoteName,
  162. IN OUT LPDWORD lpnLength
  163. )
  164. #else
  165. DWORD CMprApi :: WNetGetConnection (
  166. IN LPCSTR lpLocalName,
  167. OUT LPSTR lpRemoteName,
  168. IN OUT LPDWORD lpnLength
  169. )
  170. #endif
  171. {
  172. return m_pfnWNetGetConnection (
  173. lpLocalName,
  174. lpRemoteName,
  175. lpnLength
  176. ) ;
  177. }