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.

513 lines
10 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996.
  5. //
  6. // clsid.hxx
  7. //
  8. //--------------------------------------------------------------------------
  9. #ifndef __CLSID_HXX__
  10. #define __CLSID_HXX__
  11. // For LookupClsidData, CClsidData::Load Option parameter.
  12. // Note that LOAD_APPID skips the check in CClsidData::Load() to screen
  13. // against COM+ library aps. In the legacy case, VB sometimes loads a library
  14. // app with CoRegisterClassObject() for debugging, so, we have to let that
  15. // work.
  16. #define LOAD_NORMAL 0
  17. #define LOAD_APPID 1
  18. // _ServerTypes values
  19. #define SERVERTYPE_NONE 0
  20. #define SERVERTYPE_EXE32 1
  21. #define SERVERTYPE_SERVICE 2
  22. #define SERVERTYPE_SURROGATE 3
  23. #define SERVERTYPE_EXE16 4
  24. #define SERVERTYPE_INPROC32 5
  25. // NOTE: Both of following are dllhost.exe but complus
  26. // is more specific
  27. #define SERVERTYPE_COMPLUS 6
  28. #define SERVERTYPE_DLLHOST 7
  29. // A COM+ app configured to be an NT service
  30. #define SERVERTYPE_COMPLUS_SVC 8
  31. class CClsidData;
  32. class CAppidData;
  33. HRESULT
  34. LookupClsidData(
  35. IN GUID & Clsid,
  36. IN IComClassInfo* pComClassInfo,
  37. IN CToken * pToken,
  38. IN DWORD Option,
  39. IN OUT CClsidData **ppClsidData
  40. );
  41. HRESULT
  42. LookupAppidData(
  43. IN GUID & AppidGuid,
  44. IN CToken * pToken,
  45. OUT CAppidData ** ppAppidData
  46. );
  47. class CAppidData
  48. {
  49. public:
  50. CAppidData(
  51. IN WCHAR * pwszAppid,
  52. IN CToken * pToken
  53. );
  54. ~CAppidData();
  55. HRESULT
  56. Load(
  57. IN IComProcessInfo *pICPI
  58. );
  59. void
  60. Purge();
  61. inline WCHAR *
  62. AppidString()
  63. {
  64. return _wszAppid;
  65. }
  66. inline GUID *
  67. AppidGuid()
  68. {
  69. return &_GuidAppid;
  70. }
  71. inline BOOL
  72. ActivateAtStorage()
  73. {
  74. return _bActivateAtStorage;
  75. }
  76. inline BOOL
  77. ComPlusProcess()
  78. {
  79. // NOTE!!!!:: This is true for normal dllhost.exe regardless of
  80. // whether they are really complus or not. We won't
  81. // distinguish this in here in AppidData but in
  82. // ClsidData
  83. return _bComPlusProcess;
  84. }
  85. inline WCHAR *
  86. RemoteServerNames()
  87. {
  88. return _pwszRemoteServerNames;
  89. }
  90. inline WCHAR *
  91. RunAsUser()
  92. {
  93. return _pwszRunAsUser;
  94. }
  95. inline BOOL
  96. IsInteractiveUser()
  97. {
  98. RunAsType type;
  99. if (FAILED(_pICPI->GetRunAsType(&type)))
  100. return FALSE;
  101. return (type == RunAsInteractiveUser);
  102. }
  103. inline RunAsType
  104. GetRunAsType()
  105. {
  106. RunAsType type;
  107. if (FAILED(_pICPI->GetRunAsType(&type)))
  108. type = RunAsLaunchingUser;
  109. return type;
  110. }
  111. inline ProcessType
  112. GetProcessType()
  113. {
  114. ProcessType type;
  115. if (FAILED(_pICPI->GetProcessType(&type)))
  116. type = ProcessTypeNormal;
  117. return type;
  118. }
  119. inline WCHAR *
  120. RunAsDomain()
  121. {
  122. return _pwszRunAsDomain;
  123. }
  124. inline WCHAR *
  125. Service()
  126. {
  127. return _pwszService;
  128. }
  129. inline WCHAR *
  130. ServiceArgs()
  131. {
  132. return _pwszServiceParameters;
  133. }
  134. inline SECURITY_DESCRIPTOR *
  135. LaunchPermission()
  136. {
  137. return _pLaunchPermission;
  138. }
  139. inline BOOL
  140. GetSaferLevel(DWORD *pdwSaferLevel)
  141. {
  142. if (_fSaferLevelValid)
  143. *pdwSaferLevel = _dwSaferLevel;
  144. return _fSaferLevelValid;
  145. }
  146. BOOL
  147. CertifyServer(
  148. IN CProcess * pProcess
  149. );
  150. CNamedObject*
  151. ServerRegisterEvent();
  152. CNamedObject*
  153. ServerInitializedEvent();
  154. private:
  155. CToken * _pToken;
  156. WCHAR * _pwszService;
  157. WCHAR * _pwszServiceParameters;
  158. WCHAR * _pwszRunAsUser;
  159. WCHAR * _pwszRunAsDomain;
  160. SECURITY_DESCRIPTOR * _pLaunchPermission;
  161. DWORD _dwSaferLevel;
  162. BOOL _fSaferLevelValid;
  163. BOOL _bActivateAtStorage;
  164. WCHAR * _pwszRemoteServerNames;
  165. BOOL _bComPlusProcess;
  166. WCHAR _wszAppid[GUIDSTR_MAX];
  167. GUID _GuidAppid;
  168. IComProcessInfo* _pICPI;
  169. };
  170. class CClsidData
  171. {
  172. friend class CServerTableEntry;
  173. public:
  174. CClsidData( IN GUID & Clsid, IN CToken * pToken, IN IComClassInfo* );
  175. ~CClsidData();
  176. HRESULT
  177. Load(
  178. IN DWORD Option
  179. );
  180. void
  181. Purge();
  182. inline CToken *
  183. Token()
  184. {
  185. return _pToken;
  186. }
  187. inline GUID *
  188. ClsidGuid()
  189. {
  190. return &_Clsid;
  191. }
  192. inline WCHAR *
  193. AppidString()
  194. {
  195. return _pAppid ? _pAppid->AppidString() : NULL;
  196. }
  197. inline GUID *
  198. AppidGuid()
  199. {
  200. return _pAppid ? _pAppid->AppidGuid() : NULL;
  201. }
  202. inline DWORD
  203. ServerType()
  204. {
  205. return _ServerType;
  206. }
  207. inline BOOL
  208. IsInprocClass()
  209. {
  210. return _bIsInprocClass;
  211. }
  212. inline DWORD
  213. DllThreadModel()
  214. {
  215. return _DllThreadModel;
  216. }
  217. inline WCHAR *
  218. Server()
  219. {
  220. if ((_ServerType == SERVERTYPE_SERVICE) ||
  221. (_ServerType == SERVERTYPE_COMPLUS_SVC))
  222. return _pAppid->Service();
  223. else
  224. return _pwszServer;
  225. }
  226. inline BOOL
  227. ActivateAtStorage()
  228. {
  229. return _pAppid ? _pAppid->ActivateAtStorage() : FALSE;
  230. }
  231. inline BOOL
  232. ComPlusProcess()
  233. {
  234. return (_ServerType == SERVERTYPE_COMPLUS);
  235. }
  236. inline BOOL
  237. DllHostOrComPlusProcess()
  238. {
  239. return (ComPlusProcess() ||
  240. (_ServerType == SERVERTYPE_COMPLUS_SVC) ||
  241. (_ServerType == SERVERTYPE_DLLHOST));
  242. }
  243. inline WCHAR *
  244. DllSurrogate()
  245. {
  246. return _pwszDllSurrogate;
  247. }
  248. inline WCHAR *
  249. ServerExecutable()
  250. {
  251. return _pwszServerExecutable;
  252. }
  253. inline WCHAR *
  254. RemoteServerNames()
  255. {
  256. return _pAppid ? _pAppid->RemoteServerNames() : 0;
  257. }
  258. inline WCHAR *
  259. RunAsUser()
  260. {
  261. return _pAppid ? _pAppid->RunAsUser() : NULL;
  262. }
  263. inline BOOL
  264. IsInteractiveUser()
  265. {
  266. return _pAppid ? _pAppid->IsInteractiveUser() : FALSE;
  267. }
  268. inline BOOL
  269. HasRunAs()
  270. {
  271. return ((RunAsUser() != 0) || IsInteractiveUser());
  272. }
  273. inline WCHAR *
  274. RunAsDomain()
  275. {
  276. return _pAppid ? _pAppid->RunAsDomain() : 0;
  277. }
  278. inline WCHAR *
  279. ServiceArgs()
  280. {
  281. return _pAppid ? _pAppid->ServiceArgs() : 0;
  282. }
  283. inline SECURITY_DESCRIPTOR *
  284. LaunchPermission()
  285. {
  286. return _pAppid ? _pAppid->LaunchPermission() : 0;
  287. }
  288. inline SAFER_LEVEL_HANDLE
  289. SaferLevel()
  290. {
  291. return _hSaferLevel;
  292. }
  293. inline BOOL
  294. CertifyServer( IN CProcess * pProcess )
  295. {
  296. return _pAppid ? _pAppid->CertifyServer( pProcess ) : TRUE;
  297. }
  298. CNamedObject*
  299. ServerLaunchMutex();
  300. CNamedObject*
  301. ServerRegisterEvent();
  302. CNamedObject*
  303. ServerInitializedEvent();
  304. inline DWORD
  305. GetAcceptableContext()
  306. {
  307. return _dwAcceptableCtx;
  308. }
  309. HRESULT
  310. IsEnabledRemote()
  311. {
  312. IComClassInfo2 *pCCI2 = NULL;
  313. HRESULT hr = _pIComCI->QueryInterface(IID_IComClassInfo2, (void **)&pCCI2);
  314. if (SUCCEEDED(hr))
  315. {
  316. BOOL fEnabled;
  317. hr = pCCI2->IsEnabledRemote(&fEnabled);
  318. pCCI2->Release();
  319. if (SUCCEEDED(hr) && !fEnabled)
  320. hr = CO_E_CLASS_DISABLED;
  321. }
  322. else
  323. {
  324. // IComClassInfo2 not supported, it's enabled.
  325. hr = S_OK;
  326. }
  327. return hr;
  328. }
  329. private:
  330. HRESULT
  331. LaunchActivatorServer(
  332. IN CToken * pClientToken,
  333. IN WCHAR * pEnvBlock,
  334. IN DWORD EnvBlockLength,
  335. IN BOOL fRemoteActivation,
  336. IN BOOL fClientImpersonating,
  337. IN WCHAR* pwszWinstaDesktop,
  338. IN DWORD clsctx,
  339. OUT HANDLE * phProcess,
  340. OUT DWORD * pdwProcessId
  341. );
  342. HRESULT
  343. LaunchRunAsServer(
  344. IN CToken * pClientToken,
  345. IN BOOL fRemoteActivation,
  346. IN ActivationPropertiesIn *pActIn,
  347. IN DWORD clsctx,
  348. OUT HANDLE * phProcess,
  349. OUT DWORD * pdwProcessId,
  350. OUT void ** ppvRunAsHandle
  351. );
  352. HRESULT
  353. LaunchService(
  354. IN CToken * pClientToken,
  355. IN DWORD clsctx,
  356. OUT SC_HANDLE * phService
  357. );
  358. BOOL
  359. LaunchAllowed(
  360. IN CToken * pClientToken,
  361. IN DWORD clsctx
  362. );
  363. #if(_WIN32_WINNT >= 0x0500)
  364. HRESULT
  365. LaunchRestrictedServer(
  366. IN CToken * pClientToken,
  367. IN WCHAR * pEnvBlock,
  368. IN DWORD EnvBlockLength,
  369. IN DWORD clsctx,
  370. OUT HANDLE * phProcess,
  371. OUT DWORD * pdwProcessId
  372. );
  373. HRESULT
  374. CreateHKEYRestrictedSite(
  375. IN CToken * pToken);
  376. #endif //(_WIN32_WINNT >= 0x0500)
  377. HRESULT
  378. GetLaunchCommandLine(
  379. OUT WCHAR ** ppwszCommandLine
  380. );
  381. HRESULT
  382. AddAppPathsToEnv(
  383. IN WCHAR * pEnvBlock,
  384. IN DWORD EnvBlockLength,
  385. OUT WCHAR ** ppFinalEnvBlock
  386. );
  387. HRESULT
  388. CalculateSaferLevel();
  389. BOOL
  390. AutoSaferEnabled();
  391. HRESULT
  392. DefaultSaferLevel(
  393. DWORD *pdwSafer
  394. );
  395. HRESULT
  396. GetAAASaferToken(
  397. CToken *pClientTone,
  398. HANDLE *pTokenOut
  399. );
  400. GUID _Clsid;
  401. CAppidData * _pAppid;
  402. CToken * _pToken;
  403. BOOL _bIsInprocClass;
  404. UCHAR _ServerType;
  405. UCHAR _DllThreadModel;
  406. WCHAR * _pwszServer;
  407. WCHAR * _pwszDarwinId;
  408. WCHAR * _pwszDllSurrogate;
  409. WCHAR * _pwszServerExecutable;
  410. SAFER_LEVEL_HANDLE _hSaferLevel;
  411. IComClassInfo* _pIComCI;
  412. IClassClassicInfo* _pIClassCI;
  413. IComProcessInfo* _pICPI;
  414. DWORD _dwAcceptableCtx;
  415. WCHAR _wszClsid[GUIDSTR_MAX];
  416. };
  417. #endif // __CLSID_HXX__