Source code of Windows XP (NT5)
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.

404 lines
7.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_STATUS status = RPC_S_OK;
  53. SENS_CHAR * BindingString = NULL;
  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 = RpcStringBindingCompose(
  63. NULL, // NULL ObjUuid
  64. SENS_PROTSEQ,
  65. NULL, // Local machine
  66. SENS_ENDPOINT,
  67. NULL, // No Options
  68. &BindingString
  69. );
  70. if (BindingString != NULL)
  71. {
  72. RPC_BINDING_HANDLE hServer = NULL;
  73. status = RpcBindingFromStringBinding(BindingString, &hServer);
  74. RpcStringFree(&BindingString);
  75. if (status == RPC_S_OK)
  76. {
  77. RPC_SECURITY_QOS RpcSecQos;
  78. RpcSecQos.Version= RPC_C_SECURITY_QOS_VERSION_1;
  79. RpcSecQos.ImpersonationType= RPC_C_IMP_LEVEL_IMPERSONATE;
  80. RpcSecQos.IdentityTracking= RPC_C_QOS_IDENTITY_DYNAMIC;
  81. RpcSecQos.Capabilities= RPC_C_QOS_CAPABILITIES_MUTUAL_AUTH;
  82. status= RpcBindingSetAuthInfoEx(hServer,
  83. L"NT Authority\\System",
  84. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  85. RPC_C_AUTHN_WINNT,
  86. NULL,
  87. RPC_C_AUTHZ_NONE,
  88. (RPC_SECURITY_QOS *)&RpcSecQos);
  89. if (status != RPC_S_OK)
  90. {
  91. RpcBindingFree(&hServer);
  92. }
  93. else
  94. {
  95. ghSensNotify = hServer;
  96. }
  97. }
  98. }
  99. return (status);
  100. }
  101. #if defined(SENSNOTIFY_WINLOGON_EVENT)
  102. DWORD
  103. SensNotifyWinlogonEvent(
  104. PSENS_NOTIFY_WINLOGON pEvent
  105. )
  106. /*++
  107. Routine Description:
  108. Arguments:
  109. None.
  110. Return Value:
  111. None.
  112. --*/
  113. {
  114. RPC_STATUS RpcStatus;
  115. RpcStatus = DoRpcSetup();
  116. if (RPC_S_OK != RpcStatus)
  117. {
  118. return RpcStatus;
  119. }
  120. RpcStatus = SensApip_RPC_SensNotifyWinlogonEvent(
  121. ghSensNotify,
  122. pEvent
  123. );
  124. if (RpcStatus)
  125. {
  126. return RpcStatus;
  127. }
  128. return (ERROR_SUCCESS);
  129. }
  130. #endif // SENSNOTIFY_WINLOGON_EVENT
  131. #if defined(SENSNOTIFY_OTHER_EVENT)
  132. DWORD
  133. SensNotifyRasEvent(
  134. PSENS_NOTIFY_RAS pEvent
  135. )
  136. /*++
  137. Routine Description:
  138. Entry point for RAS to notify SENS of various RAS Events.
  139. Arguments:
  140. None.
  141. Return Value:
  142. None.
  143. --*/
  144. {
  145. RPC_STATUS RpcStatus;
  146. RpcStatus = DoRpcSetup();
  147. if (RPC_S_OK != RpcStatus)
  148. {
  149. return RpcStatus;
  150. }
  151. RpcStatus = SensApip_RPC_SensNotifyRasEvent(
  152. ghSensNotify,
  153. pEvent
  154. );
  155. if (RpcStatus)
  156. {
  157. return RpcStatus;
  158. }
  159. return (ERROR_SUCCESS);
  160. }
  161. DWORD
  162. SensNotifyNetconEvent(
  163. PSENS_NOTIFY_NETCON pEvent
  164. )
  165. /*++
  166. Routine Description:
  167. Entry point for Network UI to notify SENS of LAN Connect/Disconnect events.
  168. Arguments:
  169. pEvent - Pointer to Netcon event notification data.
  170. Return Value:
  171. S_OK, if successful.
  172. Failed hr, otherwise
  173. --*/
  174. {
  175. HRESULT hr;
  176. RPC_STATUS RpcStatus;
  177. SENS_NOTIFY_NETCON_P Data;
  178. NETCON_PROPERTIES *pNetconProperties;
  179. hr = S_OK;
  180. pNetconProperties = NULL;
  181. //
  182. // Fill-in the data.
  183. //
  184. ASSERT(pEvent && pEvent->pINetConnection);
  185. ASSERT( (pEvent->eType == SENS_NOTIFY_LAN_CONNECT)
  186. || (pEvent->eType == SENS_NOTIFY_LAN_DISCONNECT));
  187. hr = pEvent->pINetConnection->GetProperties(&pNetconProperties);
  188. if (FAILED(hr))
  189. {
  190. goto Cleanup;
  191. }
  192. if ( (NULL == pNetconProperties)
  193. || (pNetconProperties->MediaType != NCM_LAN)
  194. || ( (pNetconProperties->Status != NCS_CONNECTED)
  195. && (pNetconProperties->Status != NCS_DISCONNECTED)))
  196. {
  197. hr = HRESULT_FROM_WIN32(ERROR_INVALID_PARAMETER);
  198. goto Cleanup;
  199. }
  200. Data.eType = pEvent->eType;
  201. Data.Status = pNetconProperties->Status;
  202. Data.Type = pNetconProperties->MediaType;
  203. Data.Name = pNetconProperties->pszwName;
  204. //
  205. // Send the data across.
  206. //
  207. RpcStatus = DoRpcSetup();
  208. if (RPC_S_OK != RpcStatus)
  209. {
  210. hr = HRESULT_FROM_WIN32(RpcStatus);
  211. goto Cleanup;
  212. }
  213. RpcStatus = SensApip_RPC_SensNotifyNetconEvent(
  214. ghSensNotify,
  215. &Data
  216. );
  217. if (RpcStatus)
  218. {
  219. hr = HRESULT_FROM_WIN32(RpcStatus);
  220. goto Cleanup;
  221. }
  222. Cleanup:
  223. //
  224. // Cleanup
  225. //
  226. // Free NetconProperties, if necessary.
  227. if (pNetconProperties)
  228. {
  229. HMODULE hDll;
  230. PFN_FREE_NETCON_PROPERTIES pfnFreeNetconProperties;
  231. hDll = LoadLibrary(NETSHELL_DLL);
  232. if (NULL == hDll)
  233. {
  234. hr = HRESULT_FROM_WIN32(GetLastError());
  235. return hr;
  236. }
  237. pfnFreeNetconProperties = (PFN_FREE_NETCON_PROPERTIES)
  238. GetProcAddress(
  239. hDll,
  240. FREE_NETCON_PROPERTIES
  241. );
  242. if (NULL == pfnFreeNetconProperties)
  243. {
  244. hr = HRESULT_FROM_WIN32(GetLastError());
  245. FreeLibrary(hDll);
  246. return hr;
  247. }
  248. (*pfnFreeNetconProperties)(pNetconProperties);
  249. FreeLibrary(hDll);
  250. }
  251. return (hr);
  252. }
  253. DWORD
  254. SyncMgrExecCmd(
  255. DWORD nCmdID,
  256. DWORD nCmdExecOpt
  257. )
  258. /*++
  259. Routine Description:
  260. Private function for Syncmgr to execute work on it's behalf.
  261. Arguments:
  262. None.
  263. Return Value:
  264. None.
  265. --*/
  266. {
  267. RPC_STATUS RpcStatus;
  268. RpcStatus = DoRpcSetup();
  269. if (RPC_S_OK != RpcStatus)
  270. {
  271. return RpcStatus;
  272. }
  273. RpcStatus = SensApip_RPC_SyncMgrExecCmd(
  274. ghSensNotify,
  275. nCmdID,
  276. nCmdExecOpt
  277. );
  278. if (RpcStatus)
  279. {
  280. return RpcStatus;
  281. }
  282. return (ERROR_SUCCESS);
  283. }
  284. #endif // SENSNOTIFY_OTHER_EVENT