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.

366 lines
6.3 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. sensapip.cxx
  5. Abstract:
  6. Code for SensNotify* APIs which are called by external components
  7. to notify SENS of external events.
  8. Author:
  9. Gopal Parupudi <GopalP>
  10. [Notes:]
  11. optional-notes
  12. Revision History:
  13. GopalP 11/4/1997 Start.
  14. --*/
  15. #include <common.hxx>
  16. #include <rpc.h>
  17. #include <notify.h>
  18. #include <windows.h>
  19. //
  20. // Constants
  21. //
  22. #define FREE_NETCON_PROPERTIES "NcFreeNetconProperties"
  23. #define NETSHELL_DLL SENS_STRING("netshell.dll")
  24. //
  25. // Define these constants to include respective portions of this
  26. // file.
  27. //
  28. // #define SENSNOTIFY_OTHER_EVENT
  29. // #define SENSNOTIFY_WINLOGON_EVENT
  30. //
  31. //
  32. // Typedefs
  33. //
  34. typedef void (STDAPICALLTYPE *PFN_FREE_NETCON_PROPERTIES) (NETCON_PROPERTIES* pProps);
  35. //
  36. // Globals
  37. //
  38. RPC_BINDING_HANDLE ghSensNotify = NULL;
  39. inline RPC_STATUS
  40. DoRpcSetup(
  41. void
  42. )
  43. /*++
  44. Routine Description:
  45. Do the miscellaneous work to talk to SENS via RPC.
  46. Arguments:
  47. None.
  48. Return Value:
  49. None.
  50. --*/
  51. {
  52. RPC_BINDING_HANDLE bh = NULL;
  53. RPC_STATUS status = RPC_S_OK;
  54. //
  55. // NOTE: This is called very early in the system startup and so, it is
  56. // guaranteed to be serialized. So, a lock is not necessary.
  57. //
  58. if (ghSensNotify != NULL)
  59. {
  60. return (status);
  61. }
  62. status = BindToSensService(bh);
  63. if (status == RPC_S_OK)
  64. {
  65. ASSERT(bh);
  66. ASSERT(ghSensNotify == NULL);
  67. ghSensNotify = bh;
  68. }
  69. return (status);
  70. }
  71. #if defined(SENSNOTIFY_WINLOGON_EVENT)
  72. DWORD
  73. SensNotifyWinlogonEvent(
  74. PSENS_NOTIFY_WINLOGON pEvent
  75. )
  76. /*++
  77. Routine Description:
  78. Arguments:
  79. None.
  80. Return Value:
  81. None.
  82. --*/
  83. {
  84. RPC_STATUS RpcStatus;
  85. RpcStatus = DoRpcSetup();
  86. if (RPC_S_OK != RpcStatus)
  87. {
  88. return RpcStatus;
  89. }
  90. RpcStatus = SensApip_RPC_SensNotifyWinlogonEvent(
  91. ghSensNotify,
  92. pEvent
  93. );
  94. if (RpcStatus)
  95. {
  96. return RpcStatus;
  97. }
  98. return (ERROR_SUCCESS);
  99. }
  100. #endif // SENSNOTIFY_WINLOGON_EVENT
  101. #if defined(SENSNOTIFY_OTHER_EVENT)
  102. DWORD
  103. SensNotifyRasEvent(
  104. PSENS_NOTIFY_RAS pEvent
  105. )
  106. /*++
  107. Routine Description:
  108. Entry point for RAS to notify SENS of various RAS Events.
  109. Arguments:
  110. None.
  111. Return Value:
  112. None.
  113. --*/
  114. {
  115. RPC_STATUS RpcStatus;
  116. RpcStatus = DoRpcSetup();
  117. if (RPC_S_OK != RpcStatus)
  118. {
  119. return RpcStatus;
  120. }
  121. RpcStatus = SensApip_RPC_SensNotifyRasEvent(
  122. ghSensNotify,
  123. pEvent
  124. );
  125. if (RpcStatus)
  126. {
  127. return RpcStatus;
  128. }
  129. return (ERROR_SUCCESS);
  130. }
  131. DWORD
  132. SensNotifyNetconEvent(
  133. PSENS_NOTIFY_NETCON pEvent
  134. )
  135. /*++
  136. Routine Description:
  137. Entry point for Network UI to notify SENS of LAN Connect/Disconnect events.
  138. Arguments:
  139. pEvent - Pointer to Netcon event notification data.
  140. Return Value:
  141. S_OK, if successful.
  142. Failed hr, otherwise
  143. --*/
  144. {
  145. HRESULT hr;
  146. RPC_STATUS RpcStatus;
  147. SENS_NOTIFY_NETCON_P Data;
  148. NETCON_PROPERTIES *pNetconProperties;
  149. hr = S_OK;
  150. pNetconProperties = NULL;
  151. //
  152. // Fill-in the data.
  153. //
  154. ASSERT(pEvent && pEvent->pINetConnection);
  155. ASSERT( (pEvent->eType == SENS_NOTIFY_LAN_CONNECT)
  156. || (pEvent->eType == SENS_NOTIFY_LAN_DISCONNECT));
  157. hr = pEvent->pINetConnection->GetProperties(&pNetconProperties);
  158. if (FAILED(hr))
  159. {
  160. goto Cleanup;
  161. }
  162. if ( (NULL == pNetconProperties)
  163. || (pNetconProperties->MediaType != NCM_LAN)
  164. || ( (pNetconProperties->Status != NCS_CONNECTED)
  165. && (pNetconProperties->Status != NCS_DISCONNECTED)))
  166. {
  167. hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  168. goto Cleanup;
  169. }
  170. Data.eType = pEvent->eType;
  171. Data.Status = pNetconProperties->Status;
  172. Data.Type = pNetconProperties->MediaType;
  173. Data.Name = pNetconProperties->pszwName;
  174. //
  175. // Send the data across.
  176. //
  177. RpcStatus = DoRpcSetup();
  178. if (RPC_S_OK != RpcStatus)
  179. {
  180. hr = HRESULT_FROM_WIN32(RpcStatus);
  181. goto Cleanup;
  182. }
  183. RpcStatus = SensApip_RPC_SensNotifyNetconEvent(
  184. ghSensNotify,
  185. &Data
  186. );
  187. if (RpcStatus)
  188. {
  189. hr = HRESULT_FROM_WIN32(RpcStatus);
  190. goto Cleanup;
  191. }
  192. Cleanup:
  193. //
  194. // Cleanup
  195. //
  196. // Free NetconProperties, if necessary.
  197. if (pNetconProperties)
  198. {
  199. HMODULE hDll;
  200. PFN_FREE_NETCON_PROPERTIES pfnFreeNetconProperties;
  201. hDll = LoadLibrary(NETSHELL_DLL);
  202. if (NULL == hDll)
  203. {
  204. hr = HRESULT_FROM_WIN32(GetLastError());
  205. return hr;
  206. }
  207. pfnFreeNetconProperties = (PFN_FREE_NETCON_PROPERTIES)
  208. GetProcAddress(
  209. hDll,
  210. FREE_NETCON_PROPERTIES
  211. );
  212. if (NULL == pfnFreeNetconProperties)
  213. {
  214. hr = HRESULT_FROM_WIN32(GetLastError());
  215. FreeLibrary(hDll);
  216. return hr;
  217. }
  218. (*pfnFreeNetconProperties)(pNetconProperties);
  219. FreeLibrary(hDll);
  220. }
  221. return (hr);
  222. }
  223. DWORD
  224. SyncMgrExecCmd(
  225. DWORD nCmdID,
  226. DWORD nCmdExecOpt
  227. )
  228. /*++
  229. Routine Description:
  230. Private function for Syncmgr to execute work on it's behalf.
  231. Arguments:
  232. None.
  233. Return Value:
  234. None.
  235. --*/
  236. {
  237. RPC_STATUS RpcStatus;
  238. RpcStatus = DoRpcSetup();
  239. if (RPC_S_OK != RpcStatus)
  240. {
  241. return RpcStatus;
  242. }
  243. RpcStatus = SensApip_RPC_SyncMgrExecCmd(
  244. ghSensNotify,
  245. nCmdID,
  246. nCmdExecOpt
  247. );
  248. if (RpcStatus)
  249. {
  250. return RpcStatus;
  251. }
  252. return (ERROR_SUCCESS);
  253. }
  254. #endif // SENSNOTIFY_OTHER_EVENT