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.

604 lines
12 KiB

  1. //*************************************************************
  2. //
  3. // Copyright (c) Microsoft Corporation 1998
  4. // All rights reserved
  5. //
  6. // manapp.hxx
  7. //
  8. //*************************************************************
  9. #if !defined(__MANAPP_HXX__)
  10. #define __MANAPP_HXX__
  11. typedef struct
  12. {
  13. GUID* pCategory; /* IN */
  14. MANAGED_APPLIST* pAppList; /* IN */
  15. HANDLE hUserToken; /* IN */
  16. HANDLE hEventAppsEnumerated; /* IN */
  17. error_status_t Status; /* OUT */
  18. } ARPCONTEXT;
  19. #define PACKAGEINFO_ALLOC_COUNT 20
  20. //
  21. // The prefix to the scope of management is always "LDAP://" --
  22. // this constant refers to the length of that prefix
  23. //
  24. #define SOMID_PREFIX_LEN 7
  25. extern "C"
  26. DWORD
  27. WINAPI
  28. ForceSyncFgPolicy( LPWSTR szUserSid );
  29. class CGPOInfo;
  30. class CGPOInfoList : public CList
  31. {
  32. public:
  33. ~CGPOInfoList();
  34. BOOL
  35. Add(
  36. PGROUP_POLICY_OBJECT pGPO
  37. );
  38. CGPOInfo *
  39. Find(
  40. WCHAR * pwszGPOId
  41. );
  42. int
  43. Compare(
  44. WCHAR * pwszGPOId1,
  45. WCHAR * pwszGPOId2
  46. );
  47. };
  48. class CGPOInfo : public CListItem
  49. {
  50. friend class CGPOInfoList;
  51. friend class CManagedAppProcessor;
  52. public:
  53. CGPOInfo(
  54. PGROUP_POLICY_OBJECT pGPOInfo,
  55. BOOL & bStatus
  56. );
  57. ~CGPOInfo();
  58. WCHAR* GetSOMPath()
  59. {
  60. return _pwszSOMPath;
  61. }
  62. WCHAR* GetGPOPath()
  63. {
  64. return _pwszGPOPath;
  65. }
  66. WCHAR* GetGPOName()
  67. {
  68. return _pwszGPOName;
  69. }
  70. private:
  71. WCHAR * _pwszGPOId;
  72. WCHAR * _pwszGPOName;
  73. WCHAR * _pwszGPOPath;
  74. WCHAR* _pwszSOMPath;
  75. };
  76. class CRsopAppContext : public CRsopContext
  77. {
  78. public:
  79. enum
  80. {
  81. NONE,
  82. POLICY_REFRESH,
  83. ARPLIST,
  84. INSTALL,
  85. REMOVAL
  86. };
  87. enum
  88. {
  89. DEMAND_INSTALL_NAME,
  90. DEMAND_INSTALL_CLSID,
  91. DEMAND_INSTALL_PROGID,
  92. DEMAND_INSTALL_FILEEXT,
  93. DEMAND_INSTALL_NONE
  94. };
  95. CRsopAppContext() :
  96. CRsopContext( APPMGMTEXTENSIONGUID ),
  97. _dwContext( NONE ),
  98. _dwInstallType( DEMAND_INSTALL_NONE ),
  99. _wszDemandSpec( NULL ),
  100. _bTransition( FALSE ),
  101. _bRemovalPurge( FALSE ),
  102. _bRemoveGPOApps( FALSE ),
  103. _bForcedRefresh( FALSE ),
  104. _dwCurrentRsopVersion( 0 ),
  105. _hEventAppsEnumerated( NULL ),
  106. _StatusAbort( ERROR_SUCCESS )
  107. {}
  108. CRsopAppContext(
  109. DWORD dwContext,
  110. HANDLE hEventAppsEnumerated = NULL,
  111. APPKEY* pAppType = NULL );
  112. CRsopAppContext( PRSOP_TARGET pRsopTarget, BOOL bReportingMode ) :
  113. CRsopContext( pRsopTarget, bReportingMode, APPMGMTEXTENSIONGUID ),
  114. _dwContext( POLICY_REFRESH ),
  115. _dwInstallType( DEMAND_INSTALL_NONE ),
  116. _wszDemandSpec( NULL ),
  117. _bTransition( FALSE ),
  118. _bRemovalPurge( FALSE ),
  119. _bRemoveGPOApps( FALSE ),
  120. _bForcedRefresh( FALSE ),
  121. _dwCurrentRsopVersion( 0 ),
  122. _hEventAppsEnumerated( NULL ),
  123. _StatusAbort( ERROR_SUCCESS )
  124. {}
  125. CRsopAppContext(
  126. IWbemServices* pWbemServices,
  127. BOOL bTransition,
  128. HRESULT* phrLoggingStatus ) :
  129. CRsopContext( pWbemServices, phrLoggingStatus, APPMGMTEXTENSIONGUID ),
  130. _dwContext( POLICY_REFRESH ),
  131. _dwInstallType( DEMAND_INSTALL_NONE ),
  132. _wszDemandSpec( NULL ),
  133. _bTransition( bTransition ),
  134. _bRemovalPurge( TRUE ),
  135. _bRemoveGPOApps( FALSE ),
  136. _bForcedRefresh ( FALSE ),
  137. _dwCurrentRsopVersion( 0 ),
  138. _hEventAppsEnumerated( NULL ),
  139. _StatusAbort( ERROR_SUCCESS )
  140. {}
  141. ~CRsopAppContext();
  142. void InitializeRsopContext(
  143. HANDLE hUserToken,
  144. HKEY hkUser,
  145. BOOL bForcedRefresh,
  146. BOOL* pbNoChanges
  147. );
  148. DWORD
  149. GetContext()
  150. {
  151. return _dwContext;
  152. }
  153. DWORD GetDemandSpec( WCHAR** ppwszDemandSpec )
  154. {
  155. *ppwszDemandSpec = _wszDemandSpec;
  156. return _dwInstallType;
  157. }
  158. BOOL Transition()
  159. {
  160. return _bTransition;
  161. }
  162. BOOL
  163. PurgeRemovalEntries()
  164. {
  165. return _bRemovalPurge;
  166. }
  167. void
  168. ResetRemovalPurge()
  169. {
  170. _bRemovalPurge = FALSE;
  171. }
  172. void
  173. SetGPOAppAdd()
  174. {
  175. _bRemoveGPOApps = FALSE;
  176. }
  177. void
  178. SetGPOAppRemoval()
  179. {
  180. _bRemoveGPOApps = TRUE;
  181. }
  182. BOOL
  183. RemoveGPOApps()
  184. {
  185. return _bRemoveGPOApps;
  186. }
  187. BOOL
  188. ForcedRefresh()
  189. {
  190. return _bForcedRefresh;
  191. }
  192. HRESULT
  193. MoveAppContextState( CRsopAppContext* pRsopContext );
  194. HRESULT
  195. SetARPContext();
  196. DWORD
  197. WriteCurrentRsopVersion( HKEY hkUser );
  198. void
  199. SetPolicyAborted( DWORD Status );
  200. BOOL
  201. HasPolicyAborted();
  202. void
  203. SetAppsEnumerated();
  204. private:
  205. //
  206. // Note -- if a new data member is added below, then
  207. // MoveAppContextState needs to be updated in order to take it
  208. // into account
  209. //
  210. DWORD _dwContext;
  211. DWORD _dwInstallType;
  212. WCHAR* _wszDemandSpec;
  213. BOOL _bTransition;
  214. BOOL _bRemovalPurge;
  215. BOOL _bRemoveGPOApps;
  216. BOOL _bForcedRefresh;
  217. DWORD _dwCurrentRsopVersion;
  218. HANDLE _hEventAppsEnumerated; // event created outside this object, should not be freed by this object
  219. DWORD _StatusAbort; // This is set to something other than ERROR_SUCCESS if
  220. // policy processing aborted before we even tried to apply
  221. // (e.g. install, assign, uninstall) the app.
  222. };
  223. class CManagedAppProcessor
  224. {
  225. public:
  226. CManagedAppProcessor(
  227. DWORD dwFlags,
  228. HANDLE hUserToken,
  229. HKEY hKeyRoot,
  230. PFNSTATUSMESSAGECALLBACK pfnStatusCallback,
  231. BOOL bIncludeLegacy,
  232. BOOL bRegularPolicyRun,
  233. CRsopAppContext * pRsopContext,
  234. DWORD & Status
  235. );
  236. ~CManagedAppProcessor();
  237. BOOL
  238. AddGPO(
  239. PGROUP_POLICY_OBJECT pGPOInfo
  240. );
  241. BOOL AddGPOList(
  242. PGROUP_POLICY_OBJECT pGPOInfo
  243. );
  244. DWORD
  245. Delete();
  246. DWORD
  247. Process();
  248. inline BOOL
  249. IsUserPolicy()
  250. {
  251. return _bUser;
  252. }
  253. inline BOOL
  254. NoChanges()
  255. {
  256. return _bNoChanges;
  257. }
  258. inline BOOL
  259. Async()
  260. {
  261. return _bAsync;
  262. }
  263. inline DWORD
  264. ErrorReason()
  265. {
  266. return _ErrorReason;
  267. }
  268. inline BOOL
  269. ARPList()
  270. {
  271. return _bARPList;
  272. }
  273. inline BOOL
  274. RegularPolicyRun()
  275. {
  276. return _bRegularPolicyRun;
  277. }
  278. inline BOOL
  279. IsRemovingPolicies()
  280. {
  281. return _bDeleteGPOs;
  282. }
  283. inline CRsopAppContext*
  284. GetRsopContext()
  285. {
  286. return &_RsopContext;
  287. }
  288. inline WCHAR *
  289. LocalScriptDir()
  290. {
  291. return _pwszLocalPath;
  292. }
  293. inline HANDLE
  294. UserToken()
  295. {
  296. return _hUserToken;
  297. }
  298. inline HKEY
  299. RootKey()
  300. {
  301. return _hkRoot;
  302. }
  303. inline HKEY
  304. PolicyKey()
  305. {
  306. return _hkPolicy;
  307. }
  308. inline HKEY
  309. AppmgmtKey()
  310. {
  311. return _hkAppmgmt;
  312. }
  313. inline CGPOInfoList &
  314. GPOList()
  315. {
  316. return _GPOs;
  317. }
  318. inline CAppList &
  319. AppList()
  320. {
  321. return _Apps;
  322. }
  323. inline CAppList &
  324. ScriptList()
  325. {
  326. return _LocalScripts;
  327. }
  328. inline void
  329. LogonMsgApplying()
  330. {
  331. LogonMsg( IDS_STATUS_APPLY );
  332. }
  333. inline void
  334. LogonMsgDefault()
  335. {
  336. if ( _bUser )
  337. LogonMsg( IDS_STATUS_USER_SETTINGS );
  338. else
  339. LogonMsg( IDS_STATUS_COMPUTER_SETTINGS );
  340. }
  341. inline void
  342. LogonMsgInstall(
  343. WCHAR * pwszApp
  344. )
  345. {
  346. LogonMsg( IDS_STATUS_INSTALL, pwszApp );
  347. }
  348. inline void
  349. LogonMsgUninstall(
  350. WCHAR * pwszApp
  351. )
  352. {
  353. LogonMsg( IDS_STATUS_UNINSTALL, pwszApp );
  354. }
  355. inline DWORD
  356. Impersonate()
  357. {
  358. if ( ! GetRsopContext()->IsPlanningModeEnabled() && _bUser && ! ImpersonateLoggedOnUser( _hUserToken ) )
  359. {
  360. DebugMsg((DM_WARNING, IDS_NOIMPERSONATE, GetLastError()));
  361. return GetLastError();
  362. }
  363. return ERROR_SUCCESS;
  364. }
  365. inline void
  366. Revert()
  367. {
  368. if ( ! GetRsopContext()->IsPlanningModeEnabled() && _bUser )
  369. RevertToSelf();
  370. }
  371. DWORD
  372. GetOrderedLocalAppList(
  373. CAppList & AppList
  374. );
  375. DWORD
  376. GetLocalScriptAppList(
  377. CAppList & AppList
  378. );
  379. DWORD
  380. LoadPolicyList();
  381. DWORD
  382. SetPolicyListFromGPOList(
  383. PGROUP_POLICY_OBJECT pGPOList
  384. );
  385. DWORD
  386. MergePolicyList();
  387. DWORD
  388. GetManagedApplications(
  389. GUID * pCategory,
  390. ARPCONTEXT* pArpContext
  391. );
  392. void
  393. WriteRsopLogs();
  394. private:
  395. void
  396. LogonMsg(
  397. DWORD MsgId,
  398. ...
  399. );
  400. DWORD
  401. CreateAndSecureScriptDir();
  402. void
  403. DeleteScriptFile(
  404. GUID & DeploymentId
  405. );
  406. DWORD
  407. GetRemovedApps();
  408. HRESULT
  409. GetAppsFromDirectory();
  410. DWORD
  411. GetAppsFromLocal();
  412. BOOL
  413. DetectLostApps();
  414. DWORD
  415. GetLostApps();
  416. HRESULT
  417. FindAppInRSoP(
  418. CAppInfo * pScriptInfo,
  419. GUID * pGPOId,
  420. LONG * pRedeployCount
  421. );
  422. HRESULT
  423. GetPackageEnumeratorFromPath(
  424. WCHAR* wszClassStorePath,
  425. GUID* pCategory,
  426. DWORD dwAppFlags,
  427. IEnumPackage** ppEnumPackage);
  428. HRESULT
  429. GetDsPackageFromGPO(
  430. CGPOInfo* pGpoInfo,
  431. GUID* pDeploymentId,
  432. PACKAGEDISPINFO* pPackageInfo);
  433. HRESULT
  434. GetClassAccessFromPath(
  435. WCHAR* wszClassStorePath,
  436. IClassAccess** ppIClassAccess);
  437. HRESULT
  438. EnumerateApps(
  439. IEnumPackage * pEnumPackages
  440. );
  441. BOOL
  442. AddAppsFromDirectory(
  443. ULONG cApps,
  444. PACKAGEDISPINFO * rgPackageInfo,
  445. CAppList & AppList
  446. );
  447. DWORD
  448. GetDSQuery();
  449. DWORD
  450. CommitPolicyList();
  451. CGPOInfoList _GPOs;
  452. CAppList _Apps;
  453. CAppList _LocalScripts;
  454. CSPath _CSPath;
  455. PFNSTATUSMESSAGECALLBACK _pfnStatusCallback;
  456. WCHAR * _pwszLocalPath; // %systemroot%\system32\appmgmt\<SID>
  457. HANDLE _hUserToken;
  458. HKEY _hkRoot;
  459. HKEY _hkPolicy;
  460. HKEY _hkAppmgmt;
  461. BOOL _bUser;
  462. BOOL _bNoChanges;
  463. BOOL _bAsync;
  464. BOOL _bARPList;
  465. ULONGLONG _NewUsn;
  466. DWORD _ArchLang;
  467. BOOL _bIncludeLegacy;
  468. BOOL _bDeleteGPOs;
  469. BOOL _bRegularPolicyRun;
  470. DWORD _ErrorReason;
  471. CRsopAppContext _RsopContext;
  472. };
  473. typedef HRESULT (STDAPICALLTYPE * SHGETFOLDERPATHW)(
  474. HWND hwnd,
  475. int csidl,
  476. HANDLE hToken,
  477. DWORD dwFlags,
  478. LPWSTR lpszPath
  479. );
  480. DWORD
  481. GetScriptDirPath(
  482. HANDLE hToken,
  483. DWORD ExtraPathChars,
  484. WCHAR ** ppwszPath,
  485. DWORD * dwAllocatedSize = NULL
  486. );
  487. #endif // __MANAPP_HXX__