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.

245 lines
7.2 KiB

  1. //=================================================================
  2. //
  3. // SvrApiApi.cpp
  4. //
  5. // Copyright (c) 1999-2001 Microsoft Corporation, All Rights Reserved
  6. //
  7. //=================================================================
  8. #include "precomp.h"
  9. #include <cominit.h>
  10. #include "SvrApiApi.h"
  11. #include "DllWrapperCreatorReg.h"
  12. // {C77B8EE2-D02A-11d2-911F-0060081A46FD}
  13. static const GUID g_guidSvrApiApi =
  14. { 0xc77b8ee2, 0xd02a, 0x11d2, { 0x91, 0x1f, 0x0, 0x60, 0x8, 0x1a, 0x46, 0xfd } };
  15. static const TCHAR g_tstrSvrApi[] = _T("SVRAPI.DLL");
  16. /******************************************************************************
  17. * Register this class with the CResourceManager.
  18. *****************************************************************************/
  19. CDllApiWraprCreatrReg<CSvrApiApi, &g_guidSvrApiApi, g_tstrSvrApi> MyRegisteredSvrApiWrapper;
  20. /******************************************************************************
  21. * Constructor
  22. ******************************************************************************/
  23. CSvrApiApi::CSvrApiApi(LPCTSTR a_tstrWrappedDllName)
  24. : CDllWrapperBase(a_tstrWrappedDllName),
  25. #ifdef NTONLY
  26. m_pfnNetShareEnumSticky(NULL),
  27. m_pfnNetShareDelSticky(NULL),
  28. m_pfnNetShareCheck(NULL),
  29. #endif
  30. m_pfnNetShareEnum(NULL),
  31. m_pfnNetShareGetInfo(NULL),
  32. m_pfnNetServerGetInfo(NULL),
  33. m_pfnNetShareSetInfo(NULL),
  34. m_pfnNetShareAdd(NULL),
  35. m_pfnNetShareDel(NULL)
  36. {
  37. }
  38. /******************************************************************************
  39. * Destructor
  40. ******************************************************************************/
  41. CSvrApiApi::~CSvrApiApi()
  42. {
  43. }
  44. /******************************************************************************
  45. * Initialization function to check that we obtained function addresses.
  46. * Init should fail only if the minimum set of functions was not available;
  47. * functions added in later versions may or may not be present - it is the
  48. * client's responsibility in such cases to check, in their code, for the
  49. * version of the dll before trying to call such functions. Not doing so
  50. * when the function is not present will result in an AV.
  51. *
  52. * The Init function is called by the WrapperCreatorRegistation class.
  53. ******************************************************************************/
  54. bool CSvrApiApi::Init()
  55. {
  56. bool fRet = LoadLibrary();
  57. if(fRet)
  58. {
  59. m_pfnNetShareEnum = (PFN_SVRAPI_NET_SHARE_ENUM)
  60. GetProcAddress("NetShareEnum");
  61. m_pfnNetShareGetInfo = (PFN_SVRAPI_NET_SHARE_GET_INFO)
  62. GetProcAddress("NetShareGetInfo");
  63. m_pfnNetServerGetInfo = (PFN_SVRAPI_NET_SERVER_GET_INFO)
  64. GetProcAddress("NetServerGetInfo");
  65. m_pfnNetShareSetInfo = (PFN_SVRAPI_NET_SHARE_SET_INFO)
  66. GetProcAddress("NetShareSetInfo");
  67. m_pfnNetShareAdd = (PFN_SVRAPI_NET_SHARE_ADD)
  68. GetProcAddress("NetShareAdd");
  69. m_pfnNetShareDel = (PFN_SVRAPI_NET_SHARE_DEL)
  70. GetProcAddress("NetShareDel");
  71. #ifdef NTONLY
  72. m_pfnNetShareEnumSticky = (PFN_SVRAPI_NET_SHARE_ENUM_STICKY)
  73. GetProcAddress("NetShareEnumSticky");
  74. m_pfnNetShareDelSticky = (PFN_SVRAPI_NET_SHARE_DEL_STICKY)
  75. GetProcAddress("NetShareDelSticky");
  76. m_pfnNetShareCheck = (PFN_SVRAPI_NET_SHARE_CHECK)
  77. GetProcAddress("NetShareCheck");
  78. #endif
  79. // All these functions are considered required for all versions of
  80. // this dll. Hence return false if didn't get one or more of them.
  81. if(
  82. #ifdef NTONLY
  83. m_pfnNetShareEnumSticky == NULL ||
  84. m_pfnNetShareDelSticky == NULL ||
  85. m_pfnNetShareCheck == NULL ||
  86. #endif
  87. m_pfnNetShareEnum == NULL ||
  88. m_pfnNetShareGetInfo == NULL ||
  89. m_pfnNetServerGetInfo == NULL ||
  90. m_pfnNetShareSetInfo == NULL ||
  91. m_pfnNetShareAdd == NULL ||
  92. m_pfnNetShareDel == NULL )
  93. {
  94. fRet = false;
  95. }
  96. }
  97. return fRet;
  98. }
  99. /******************************************************************************
  100. * Member functions wrapping SvrApi api functions. Add new functions here
  101. * as required.
  102. ******************************************************************************/
  103. NET_API_STATUS NET_API_FUNCTION CSvrApiApi::NetShareEnum
  104. (
  105. char FAR *a_servername,
  106. short a_level,
  107. char FAR *a_bufptr,
  108. unsigned short a_prefmaxlen,
  109. unsigned short FAR *a_entriesread,
  110. unsigned short FAR *a_totalentries
  111. )
  112. {
  113. return m_pfnNetShareEnum(a_servername, a_level, a_bufptr, a_prefmaxlen,
  114. a_entriesread, a_totalentries);
  115. }
  116. NET_API_STATUS NET_API_FUNCTION CSvrApiApi::NetShareGetInfo
  117. (
  118. char FAR *a_servername,
  119. char FAR *a_netname,
  120. short a_level,
  121. char FAR *a_bufptr,
  122. unsigned short a_buflen,
  123. unsigned short FAR *a_totalavail
  124. )
  125. {
  126. return m_pfnNetShareGetInfo(a_servername, a_netname, a_level,
  127. a_bufptr, a_buflen, a_totalavail);
  128. }
  129. NET_API_STATUS NET_API_FUNCTION CSvrApiApi::NetServerGetInfo
  130. (
  131. char FAR *a_servername,
  132. short a_level,
  133. char FAR *a_bufptr,
  134. unsigned short a_buflen,
  135. unsigned short FAR *a_totalavail
  136. )
  137. {
  138. return m_pfnNetServerGetInfo(a_servername, a_level, a_bufptr, a_buflen,
  139. a_totalavail);
  140. }
  141. #ifdef NTONLY
  142. NET_API_STATUS NET_API_FUNCTION CSvrApiApi::NetShareEnumSticky
  143. (
  144. LPTSTR a_servername,
  145. DWORD a_level,
  146. LPBYTE *a_bufptr,
  147. DWORD a_prefmaxlen,
  148. LPDWORD a_entriesread,
  149. LPDWORD a_totalentries,
  150. LPDWORD a_resume_handle
  151. )
  152. {
  153. return m_pfnNetShareEnumSticky(a_servername, a_level, a_bufptr,
  154. a_prefmaxlen,a_entriesread,
  155. a_totalentries, a_resume_handle);
  156. }
  157. #endif
  158. NET_API_STATUS NET_API_FUNCTION CSvrApiApi::NetShareSetInfo
  159. (
  160. const char FAR *a_servername,
  161. const char FAR *a_netname,
  162. short a_level,
  163. const char FAR *a_buf,
  164. unsigned short a_cbBuffer,
  165. short a_sParmNum
  166. )
  167. {
  168. return m_pfnNetShareSetInfo(a_servername, a_netname, a_level,
  169. a_buf, a_cbBuffer, a_sParmNum);
  170. }
  171. NET_API_STATUS NET_API_FUNCTION CSvrApiApi::NetShareAdd
  172. (
  173. const char FAR *a_servername,
  174. short a_level,
  175. const char FAR *a_buf,
  176. unsigned short a_cbBuffer
  177. )
  178. {
  179. return m_pfnNetShareAdd(a_servername, a_level, a_buf , a_cbBuffer);
  180. }
  181. NET_API_STATUS NET_API_FUNCTION CSvrApiApi::NetShareDel
  182. (
  183. LPTSTR a_servername,
  184. LPTSTR a_netname,
  185. DWORD a_reserved
  186. )
  187. {
  188. return m_pfnNetShareDel(a_servername, a_netname, a_reserved);
  189. }
  190. #ifdef NTONLY
  191. NET_API_STATUS NET_API_FUNCTION CSvrApiApi::NetShareDelSticky
  192. (
  193. LPTSTR a_servername,
  194. LPTSTR a_netname,
  195. DWORD a_reserved
  196. )
  197. {
  198. return m_pfnNetShareDelSticky(a_servername, a_netname, a_reserved);
  199. }
  200. #endif
  201. #ifdef NTONLY
  202. NET_API_STATUS NET_API_FUNCTION CSvrApiApi::NetShareCheck
  203. (
  204. LPTSTR a_servername,
  205. LPTSTR a_device,
  206. LPDWORD a_type
  207. )
  208. {
  209. return m_pfnNetShareCheck(a_servername, a_device, a_type);
  210. }
  211. #endif