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.

329 lines
11 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1997 - 1999
  3. Module Name:
  4. common.hxx
  5. Abstract:
  6. Header file for SENS configuration tool code.
  7. Author:
  8. Gopal Parupudi <GopalP>
  9. [Notes:]
  10. optional-notes
  11. Revision History:
  12. GopalP 11/12/1997 Start.
  13. --*/
  14. #ifndef __COMMON_HXX__
  15. #define __COMMON_HXX__
  16. //
  17. // Do not turn it on in retail builds accidentally.
  18. //
  19. //#define DETAIL_DEBUG
  20. //
  21. // Include platform independent stuff
  22. //
  23. #include <sysinc.h>
  24. //
  25. // Constants
  26. //
  27. #define SENS_SERVICEA "SENS"
  28. #define SENS_SERVICE SENS_STRING("SENS")
  29. #define SENS_PROTSEQ SENS_STRING("ncalrpc")
  30. #define SENS_ENDPOINT SENS_STRING("senssvc")
  31. #define SENS_STARTED_EVENT SENS_STRING("SENS Started Event")
  32. #define DEFAULT_LAN_CONNECTION_NAME SENS_BSTR("LAN Connection")
  33. #define DEFAULT_WAN_CONNECTION_NAME SENS_BSTR("WAN Connection")
  34. #define DEFAULT_LAN_BANDWIDTH 10000000 // 10.0 mega-bits/sec
  35. #define DEFAULT_WAN_BANDWIDTH 28800 // 28.8 kilo-bits/sec
  36. #define MAX_DESTINATION_LENGTH 512
  37. #define MAX_QUERY_SIZE 512
  38. // Sens Configuration related constants
  39. #define SENS_REGISTRY_KEY SENS_STRING("SOFTWARE\\Microsoft\\Mobile\\SENS")
  40. #define SENS_AUTOSTART_KEY SENS_STRING("Software\\Microsoft\\Windows\\CurrentVersion\\Webcheck")
  41. #define SENS_AUTOSTART_VALUE SENS_STRING("LoadSENS")
  42. #define SENS_AUTOSTART_ENABLE SENS_STRING("Yes")
  43. #define SENS_AUTOSTART_DISABLE SENS_STRING("No")
  44. #define SENS_AUTOSTART_BINARY SENS_STRING("LoadWc.exe /M") // M for Mobile
  45. #define SENS_CONFIGURATION_DLL SENS_STRING("SensCfg.Dll")
  46. #define IS_SENS_CONFIGURED SENS_STRING("Configured")
  47. #define SENS_DEBUG_LEVEL SENS_STRING("Debug")
  48. #define SENS_REGISTER_FUNCTION "SensRegister"
  49. #define CONFIG_VERSION_CURRENT 0x00000020
  50. #define CONFIG_VERSION_NONE 0x00000000
  51. // Sens Cache related constants
  52. #define SENS_CACHE_NAME SENS_STRING("SENS Information Cache")
  53. #define SENS_CACHE_SIZE 256 // 32 DWORDs
  54. #define SENS_CACHE_VERSION 0x00000002
  55. #define CACHE_VALID_INTERVAL 3*60*1000 // 3 minutes
  56. // Logging Levels
  57. #define SENS_WARN 0x00000001
  58. #define SENS_INFO 0x00000002
  59. #define SENS_MEM 0x00000004
  60. #define SENS_DBG 0x00000008
  61. #define SENS_ERR 0x00000010
  62. #define SENS_ALL 0xFFFFFFFF
  63. #if defined(SENS_CHICAGO)
  64. #define AOL_PLATFORM
  65. #error NOT SUPPORTED IN THE CODE BASE ANY MORE
  66. #endif // SENS_CHICAGO
  67. #if DBG
  68. ULONG _cdecl
  69. SensDbgPrintA(
  70. CHAR * Format,
  71. ...
  72. );
  73. ULONG _cdecl
  74. SensDbgPrintW(
  75. WCHAR * Format,
  76. ...
  77. );
  78. void
  79. EnableDebugOutputIfNecessary(
  80. void
  81. );
  82. #endif // DBG
  83. //
  84. // SID setup
  85. //
  86. const SID LocalSystem = { 1, 1, SECURITY_NT_AUTHORITY, SECURITY_LOCAL_SYSTEM_RID};
  87. //
  88. // RPC setup
  89. //
  90. inline RPC_STATUS BindToLRpcService(RPC_BINDING_HANDLE &bh, PWSTR stringBinding)
  91. {
  92. RPC_STATUS status;
  93. PSID LocalSystemSid = (PSID)&LocalSystem;
  94. RPC_SECURITY_QOS_V3 RpcSecQos;
  95. ASSERT(RtlValidSid(LocalSystemSid));
  96. bh = NULL;
  97. status = RpcBindingFromStringBinding(stringBinding, &bh);
  98. if (RPC_S_OK != status)
  99. {
  100. return (status);
  101. }
  102. RpcSecQos.Version= RPC_C_SECURITY_QOS_VERSION_3;
  103. RpcSecQos.ImpersonationType= RPC_C_IMP_LEVEL_IMPERSONATE;
  104. RpcSecQos.IdentityTracking= RPC_C_QOS_IDENTITY_DYNAMIC;
  105. RpcSecQos.Capabilities= RPC_C_QOS_CAPABILITIES_MUTUAL_AUTH;
  106. RpcSecQos.AdditionalSecurityInfoType = 0;
  107. RpcSecQos.u.HttpCredentials = NULL;
  108. RpcSecQos.Sid = (PVOID)LocalSystemSid;
  109. status= RpcBindingSetAuthInfoEx(bh,
  110. NULL,
  111. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  112. RPC_C_AUTHN_WINNT,
  113. NULL,
  114. RPC_C_AUTHZ_NONE,
  115. (RPC_SECURITY_QOS *)&RpcSecQos);
  116. if (RPC_S_OK != status)
  117. {
  118. RpcBindingFree(&bh);
  119. }
  120. return(status);
  121. }
  122. inline RPC_STATUS BindToSensService(RPC_BINDING_HANDLE &bh)
  123. {
  124. return BindToLRpcService(bh, SENS_PROTSEQ L":[" SENS_ENDPOINT L"]");
  125. }
  126. inline BOOL IsRpcCallerLocalSystem()
  127. /*++
  128. Routine Description:
  129. Callable on dispatched RPC threads. Checks that the caller of
  130. the method is Local System.
  131. Return Value:
  132. TRUE - Caller is local system
  133. FALSE - Caller is NOT local system
  134. --*/
  135. {
  136. if (RPC_S_OK != RpcImpersonateClient(0))
  137. {
  138. return RPC_S_ACCESS_DENIED;
  139. }
  140. PSID LocalSystemSid = (PSID)&LocalSystem;
  141. ASSERT(RtlValidSid(LocalSystemSid));
  142. BOOL IsMember = FALSE;
  143. if (!CheckTokenMembership(0, // Use thread token
  144. LocalSystemSid,
  145. &IsMember))
  146. {
  147. SensPrintToDebugger(SENS_DBG, ("CheckTokenMembership failed %d\n", GetLastError()));
  148. }
  149. RpcRevertToSelf();
  150. return IsMember;
  151. }
  152. //
  153. // Macros
  154. //
  155. /*++
  156. Important Notes:
  157. a. The following variables need to be defined before using these macros:
  158. HRESULT hr;
  159. LPOLESTR strGuid;
  160. b. Also, strGuid needs to be initialized to NULL.
  161. c. The function has to return an HRESULT
  162. d. The function has to have a "Cleanup" label which is the one
  163. (and only one) exit from the function.
  164. e. The function should FreeStr(strGuid); during the cleanup phase.
  165. --*/
  166. #define AllocateBstrFromString(_BSTR_, _STRING_) \
  167. \
  168. _BSTR_ = SysAllocString(_STRING_); \
  169. if (_BSTR_ == NULL) \
  170. { \
  171. SensPrintToDebugger(SENS_ERR, ("SENS: SysAllocString(%s) failed!\n", _STRING_)); \
  172. hr = E_OUTOFMEMORY; \
  173. goto Cleanup; \
  174. }
  175. #define AllocateStrFromGuid(_STR_, _GUID_) \
  176. \
  177. /* Check to see if strGuid is non-NULL. If so, delete it. */ \
  178. if (NULL != strGuid) \
  179. { \
  180. FreeStr(strGuid); \
  181. strGuid = NULL; \
  182. } \
  183. \
  184. hr = StringFromIID(_GUID_, &_STR_); \
  185. if (FAILED(hr)) \
  186. { \
  187. SensPrintA(SENS_ERR, ("SENS: StringFromIID() returned <%x>\n", hr));\
  188. goto Cleanup; \
  189. }
  190. #define AllocateBstrFromGuid(_BSTR_, _GUID_) \
  191. \
  192. AllocateStrFromGuid(strGuid, _GUID_); \
  193. \
  194. AllocateBstrFromString(_BSTR_, strGuid);
  195. #define FreeStr(_STR_) \
  196. \
  197. /* Check to see if _STR_ is non-NULL. If so, delete it. */ \
  198. if (NULL != _STR_) \
  199. { \
  200. CoTaskMemFree(_STR_); \
  201. _STR_ = NULL; \
  202. }
  203. #define FreeBstr(_BSTR_) \
  204. \
  205. SysFreeString(_BSTR_);
  206. #define InitializeBstrVariant(_PVARIANT_, _BSTR_) \
  207. \
  208. VariantInit(_PVARIANT_); \
  209. \
  210. (_PVARIANT_)->vt = VT_BSTR; \
  211. (_PVARIANT_)->bstrVal = _BSTR_;
  212. #define InitializeDwordVariant(_PVARIANT_, _DWORD_) \
  213. \
  214. VariantInit(_PVARIANT_); \
  215. \
  216. (_PVARIANT_)->vt = VT_UI4; \
  217. (_PVARIANT_)->ulVal = _DWORD_;
  218. #define FreeVariant(_PVARIANT_) \
  219. \
  220. VariantClear(_PVARIANT_);
  221. /*++
  222. Notes:
  223. a. This macro can be called only once in a function since it defines a
  224. local variable.
  225. b. If any function in this macro fails, we ignore the error.
  226. --*/
  227. #if DBG
  228. #define DebugTraceGuid(_FUNCTION_NAME_, _REFIID_) \
  229. \
  230. SensPrintA(SENS_INFO, ("\t| " _FUNCTION_NAME_ " called on the following"\
  231. " IID...\n")); \
  232. LPOLESTR lpsz = NULL; \
  233. StringFromIID(_REFIID_, &lpsz); \
  234. if (lpsz != NULL) \
  235. { \
  236. SensPrintW(SENS_INFO, (L"\t| IID is %s\n", lpsz)); \
  237. CoTaskMemFree(lpsz); \
  238. } \
  239. #else // RETAIL
  240. #define DebugTraceGuid(_FUNCTION_NAME_, _REFIID_)
  241. #endif // DBG
  242. #endif // __COMMON_HXX__