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.

236 lines
6.3 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. onestop.hxx
  5. Abstract:
  6. This file contains the common functions that are helpful in notifying
  7. OneStop of logon/logoff events.
  8. Author:
  9. Gopal Parupudi <GopalP>
  10. Notes:
  11. a. This is being used in senslogn.dll on NT5.
  12. b. It is also being used in sens.dll on NT4 and Win9x.
  13. Revision History:
  14. GopalP 4/29/1998 Start.
  15. --*/
  16. #include <mobsyncp.h>
  17. #include "onestop.hxx"
  18. HRESULT
  19. SensNotifyOneStop(
  20. HANDLE hToken,
  21. TCHAR *pCommandLine,
  22. BOOL bSync
  23. )
  24. {
  25. TCHAR szCommandLine[256];
  26. DWORD dwLastError;
  27. STARTUPINFO si;
  28. PROCESS_INFORMATION ProcessInformation;
  29. dwLastError = 0;
  30. // CreateProcess* APIs require an editable buffer for command-line parameter
  31. HRESULT hr = StringCchCopy(szCommandLine, 256, pCommandLine);
  32. ASSERT(SUCCEEDED(hr));
  33. // Fill in the STARTUPINFO structure.
  34. memset(&si, 0x0, sizeof(STARTUPINFO));
  35. si.cb = sizeof(STARTUPINFO);
  36. si.lpReserved = NULL;
  37. si.lpTitle = NULL;
  38. si.lpDesktop = NULL;
  39. si.dwX = 0x0;
  40. si.dwY = 0x0;
  41. si.dwXSize = 0x0;
  42. si.dwYSize = 0x0;
  43. si.dwFlags = 0x0;
  44. si.wShowWindow = SW_SHOW;
  45. si.lpReserved2 = NULL;
  46. si.cbReserved2 = 0;
  47. LogMessage((SENSLOGN "[%d] Launching OneStop...\n", GetTickCount()));
  48. if (CreateProcessAsUser(
  49. hToken, // Handle to the Token of the logged-on user
  50. NULL, // Name of the executable module
  51. szCommandLine, // Command-line string
  52. NULL, // Security attributes
  53. NULL, // Thread security attributes
  54. FALSE, // Don't inherit handles
  55. 0, // Creation flags
  56. NULL, // New environment block
  57. NULL, // Current directory name
  58. &si, // Startup info
  59. &ProcessInformation // Process information
  60. ))
  61. {
  62. //
  63. // Wait until the process terminates
  64. //
  65. if (bSync)
  66. {
  67. LogMessage((SENSLOGN "[%d] Waiting for OneStop to return...\n", GetTickCount()));
  68. WaitForSingleObject(ProcessInformation.hProcess, INFINITE);
  69. LogMessage((SENSLOGN "[%d] OneStop returned successfully.\n", GetTickCount()));
  70. }
  71. CloseHandle(ProcessInformation.hProcess);
  72. CloseHandle(ProcessInformation.hThread);
  73. return S_OK;
  74. }
  75. else
  76. {
  77. dwLastError = GetLastError();
  78. SensPrintToDebugger(SENS_DBG, (SENSLOGN "SensNotifyOneStop() - CreateProcessXXX() "
  79. "failed with 0x%x\n", dwLastError));
  80. return HRESULT_FROM_WIN32(dwLastError);
  81. }
  82. LogMessage((SENSLOGN "[%d] Successfully notified OneStop.\n", GetTickCount()));
  83. return S_OK;
  84. }
  85. BOOL
  86. IsAutoSyncEnabled(
  87. HANDLE hToken,
  88. DWORD dwMask
  89. )
  90. {
  91. HKEY hKeyAutoSync;
  92. LONG lResult;
  93. BOOL bEnabled;
  94. DWORD dwType;
  95. DWORD dwAutoSyncFlags;
  96. DWORD cbData;
  97. LPBYTE lpbData;
  98. hKeyAutoSync = NULL;
  99. lResult = 0;
  100. bEnabled = FALSE;
  101. dwType = 0x0;
  102. dwAutoSyncFlags = 0x0;
  103. cbData = 0x0;
  104. lpbData = NULL;
  105. //
  106. // Open AutoSync sub-key for this machine.
  107. //
  108. lResult = RegOpenKeyEx(
  109. HKEY_LOCAL_MACHINE, // Handle of the open Key
  110. AUTOSYNC_KEY, // Name of the sub-key
  111. 0, // Reserved (MBZ)
  112. KEY_QUERY_VALUE, // Security access mask
  113. &hKeyAutoSync // Address of the handle of new key
  114. );
  115. if (lResult != ERROR_SUCCESS)
  116. {
  117. SensPrintToDebugger(SENS_DBG, (SENSLOGN "RegOpenKeyEx(AUTOSYNC) failed with 0x%x\n", lResult));
  118. goto Cleanup;
  119. }
  120. //
  121. // Query the Flags value
  122. //
  123. lpbData = (LPBYTE) &dwAutoSyncFlags;
  124. cbData = sizeof(DWORD);
  125. lResult = RegQueryValueEx(
  126. hKeyAutoSync, // Handle of the sub-key
  127. AUTOSYNC_FLAGS, // Name of the Value
  128. NULL, // Reserved (MBZ)
  129. &dwType, // Address of the type of the Value
  130. lpbData, // Address of the data of the Value
  131. &cbData // Address of size of data of the Value
  132. );
  133. if (lResult != ERROR_SUCCESS)
  134. {
  135. LogMessage((SENSLOGN "RegQueryValueEx(AUTOSYNC_FLAGS) failed with 0x%x\n", lResult));
  136. goto Cleanup;
  137. }
  138. ASSERT(dwType == REG_DWORD);
  139. //
  140. // Check to see if the Mask bit is set
  141. //
  142. if (dwMask == AUTOSYNC_ON_STARTSHELL)
  143. {
  144. if ( (dwAutoSyncFlags & AUTOSYNC_LAN_LOGON)
  145. || (dwAutoSyncFlags & AUTOSYNC_WAN_LOGON))
  146. {
  147. LogMessage((SENSLOGN "AutoSync is enabled for StartShell\n"));
  148. bEnabled = TRUE;
  149. goto Cleanup;
  150. }
  151. else
  152. {
  153. LogMessage((SENSLOGN "AutoSync is NOT enabled for Logon\n"));
  154. }
  155. }
  156. else
  157. if (dwMask == AUTOSYNC_ON_LOGOFF)
  158. {
  159. if ( (dwAutoSyncFlags & AUTOSYNC_LAN_LOGOFF)
  160. || (dwAutoSyncFlags & AUTOSYNC_WAN_LOGOFF))
  161. {
  162. LogMessage((SENSLOGN "AutoSync is enabled for Logoff\n"));
  163. bEnabled = TRUE;
  164. goto Cleanup;
  165. }
  166. else
  167. {
  168. LogMessage((SENSLOGN "AutoSync is NOT enabled for Logoff\n"));
  169. }
  170. }
  171. else
  172. if (dwMask == AUTOSYNC_ON_SCHEDULE)
  173. {
  174. if (dwAutoSyncFlags != NULL)
  175. {
  176. LogMessage((SENSLOGN "AutoSync is enabled for Schedule\n"));
  177. bEnabled = TRUE;
  178. goto Cleanup;
  179. }
  180. else
  181. {
  182. LogMessage((SENSLOGN "AutoSync is NOT enabled for Schedule\n"));
  183. }
  184. }
  185. //
  186. // Autosync is not enabled.
  187. //
  188. Cleanup:
  189. //
  190. // Cleanup
  191. //
  192. if (hKeyAutoSync)
  193. {
  194. RegCloseKey(hKeyAutoSync);
  195. }
  196. return bEnabled;
  197. }