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.

224 lines
5.6 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998.
  5. //
  6. // File: RasProc.cpp
  7. //
  8. // Contents: Exports used by Ras for doing Pending Disconnect
  9. //
  10. // Classes:
  11. //
  12. // Notes:
  13. //
  14. // History: 09-Jan-98 rogerg Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. // Windows Header Files:
  18. #include <windows.h>
  19. #include <commctrl.h>
  20. #include <objbase.h>
  21. #include <strsafe.h>
  22. #include "mobsync.h"
  23. #include "mobsyncp.h"
  24. #include "debug.h"
  25. #include "alloc.h"
  26. #include "critsect.h"
  27. #include "netapi.h"
  28. #include "syncmgrr.h"
  29. #include "rasui.h"
  30. #include "dllreg.h"
  31. #include "cnetapi.h"
  32. #include "rasproc.h"
  33. #ifndef ARRAYSIZE
  34. #define ARRAYSIZE(x) (sizeof(x) / sizeof(x[0]))
  35. #endif
  36. //+-------------------------------------------------------------------
  37. //
  38. // Function: SyncMgrRasProc
  39. //
  40. // Synopsis: Main entry point for RAS to call to perform
  41. // a pending disconnect.
  42. //
  43. // Arguments:
  44. //
  45. //
  46. // Notes:
  47. //
  48. //--------------------------------------------------------------------
  49. LRESULT CALLBACK SyncMgrRasProc(UINT uMsg,WPARAM wParam, LPARAM lParam)
  50. {
  51. switch(uMsg)
  52. {
  53. case SYNCMGRRASPROC_QUERYSHOWSYNCUI:
  54. return SyncMgrRasQueryShowSyncUI(wParam,lParam);
  55. break;
  56. case SYNCMGRRASPROC_SYNCDISCONNECT:
  57. return SyncMgrRasDisconnect(wParam,lParam);
  58. break;
  59. default:
  60. AssertSz(0,"Unknown RasProc Message");
  61. break;
  62. };
  63. return -1;
  64. }
  65. //+-------------------------------------------------------------------
  66. //
  67. // Function: SyncMgrRasQueryShowSyncUI
  68. //
  69. // Synopsis: Called by RAS to determine if Ras Should show
  70. // the Disconnect checkbox and what state it should be.
  71. //
  72. // Arguments:
  73. // wParam = 0
  74. // lParam = Pointer to SYNCMGRQUERYSHOWSYNCUI structure
  75. //
  76. // Notes:
  77. //
  78. //--------------------------------------------------------------------
  79. LRESULT SyncMgrRasQueryShowSyncUI(WPARAM wParam,LPARAM lParam)
  80. {
  81. CNetApi *pNetApi;
  82. SYNCMGRQUERYSHOWSYNCUI *pQueryStruct = (SYNCMGRQUERYSHOWSYNCUI *) lParam;
  83. LRESULT lResult = -1;
  84. if (pQueryStruct->cbSize != sizeof(SYNCMGRQUERYSHOWSYNCUI))
  85. {
  86. Assert(pQueryStruct->cbSize == sizeof(SYNCMGRQUERYSHOWSYNCUI));
  87. return -1;
  88. }
  89. pQueryStruct->fShowCheckBox = FALSE;
  90. pQueryStruct->nCheckState = BST_UNCHECKED;
  91. pNetApi = new CNetApi();
  92. if (!pNetApi)
  93. {
  94. AssertSz(0,"Failed to Load Ras");
  95. return -1;
  96. }
  97. RegSetUserDefaults(); // Make Sure the UserDefaults are up to date
  98. CONNECTIONSETTINGS connectSettings;
  99. // Review, should just pass this to Function
  100. if (FAILED(StringCchCopy(connectSettings.pszConnectionName,
  101. ARRAYSIZE(connectSettings.pszConnectionName),
  102. pQueryStruct->pszConnectionName)))
  103. {
  104. return -1;
  105. }
  106. // look up preferences for this entry and see if disconnect has been chosen.
  107. lResult = 0; // return NOERROR even if no entry is found
  108. if (RegGetAutoSyncSettings(&connectSettings))
  109. {
  110. if (connectSettings.dwLogoff)
  111. {
  112. pQueryStruct->fShowCheckBox = TRUE;
  113. pQueryStruct->nCheckState = BST_CHECKED;
  114. }
  115. }
  116. pNetApi->Release();
  117. return lResult;
  118. }
  119. //+-------------------------------------------------------------------
  120. //
  121. // Function: SyncMgrRasDisconnect
  122. //
  123. // Synopsis: Main entry point for RAS to call to perform
  124. // a pending disconnect.
  125. //
  126. // Arguments:
  127. // wParam = 0
  128. // lParam = Pointer to SYNCMGRSYNCDISCONNECT structure
  129. //
  130. // Notes:
  131. //
  132. //--------------------------------------------------------------------
  133. LRESULT SyncMgrRasDisconnect(WPARAM wParam,LPARAM lParam)
  134. {
  135. CNetApi *pNetApi;
  136. SYNCMGRSYNCDISCONNECT *pDisconnectStruct = (SYNCMGRSYNCDISCONNECT *) lParam;
  137. TCHAR szEntry[RAS_MaxEntryName + 1];
  138. if (pDisconnectStruct->cbSize != sizeof(SYNCMGRSYNCDISCONNECT))
  139. {
  140. Assert(pDisconnectStruct->cbSize == sizeof(SYNCMGRSYNCDISCONNECT));
  141. return -1;
  142. }
  143. pNetApi = new CNetApi();
  144. if (!pNetApi)
  145. {
  146. AssertSz(0,"Failed to Load Ras");
  147. return -1;
  148. }
  149. HRESULT hr;
  150. LPUNKNOWN lpUnk;
  151. // invoke SyncMgr.exe informing it is a Logoff and then wait in
  152. // a message loop until the event we pass in gets signalled.
  153. if (FAILED(StringCchCopy(szEntry, ARRAYSIZE(szEntry), pDisconnectStruct->pszConnectionName)))
  154. {
  155. return -1;
  156. }
  157. hr = CoInitialize(NULL);
  158. if (SUCCEEDED(hr))
  159. {
  160. hr = CoCreateInstance(CLSID_SyncMgrp,NULL,CLSCTX_SERVER,IID_IUnknown,(void **) &lpUnk);
  161. if (NOERROR == hr)
  162. {
  163. LPPRIVSYNCMGRSYNCHRONIZEINVOKE pSynchInvoke = NULL;
  164. hr = lpUnk->QueryInterface(IID_IPrivSyncMgrSynchronizeInvoke,
  165. (void **) &pSynchInvoke);
  166. if (NOERROR == hr)
  167. {
  168. // should have everything we need
  169. hr = pSynchInvoke->RasPendingDisconnect(
  170. (RAS_MaxEntryName + 1)*sizeof(TCHAR),
  171. (BYTE *) szEntry);
  172. pSynchInvoke->Release();
  173. }
  174. lpUnk->Release();
  175. }
  176. CoUninitialize();
  177. }
  178. pNetApi->Release();
  179. return 0;
  180. }