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.

539 lines
16 KiB

  1. /************************************************************************
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name :
  4. bitsext.h
  5. Abstract :
  6. Main file for snapin.
  7. Author :
  8. Revision History :
  9. ***********************************************************************/
  10. #ifndef _BITSEXT_H_
  11. #define _BITSEXT_H_
  12. #include <smartptr.h>
  13. typedef SmartRefPointer<ITask> SmartITaskPointer;
  14. typedef SmartRefPointer<ITaskTrigger> SmartITaskTriggerPointer;
  15. typedef SmartRefPointer<IEnumWorkItems> SmartIEnumWorkItemsPointer;
  16. typedef SmartRefPointer<ITaskScheduler> SmartITaskSchedulerPointer;
  17. typedef SmartRefPointer<IPersistFile> SmartIPersistFilePointer;
  18. typedef SmartRefPointer<IMSAdminBase> SmartIMSAdminBasePointer;
  19. typedef SmartRefPointer<IADs> SmartIADsPointer;
  20. // Event Log Source
  21. const WCHAR * const EVENT_LOG_SOURCE_NAME=L"BITS Extensions";
  22. const WCHAR * const EVENT_LOG_KEY_NAME=L"SYSTEM\\CurrentControlSet\\Services\\EventLog\\Application\\BITS Extensions";
  23. #include "beventlog.h"
  24. // IIS MMC node types
  25. const GUID g_IISInstanceNode = {0xa841b6c7, 0x7577, 0x11d0, {0xbb, 0x1f, 0x00, 0xa0, 0xc9, 0x22, 0xe7, 0x9c}};
  26. const GUID g_IISChildNode = {0xa841b6c8, 0x7577, 0x11d0, {0xbb, 0x1f, 0x00, 0xa0, 0xc9, 0x22, 0xe7, 0x9c}};
  27. class CBITSExtensionSetup;
  28. class CNonDelegatingIUnknown : public IUnknown
  29. {
  30. ULONG m_cref;
  31. CBITSExtensionSetup *m_DelegatingIUnknown;
  32. public:
  33. CNonDelegatingIUnknown( CBITSExtensionSetup * DelegatingIUnknown );
  34. STDMETHODIMP QueryInterface(REFIID riid, void **ppvObject);
  35. STDMETHODIMP_(ULONG) AddRef(void);
  36. STDMETHODIMP_(ULONG) Release(void);
  37. };
  38. class CBITSExtensionSetup : public IBITSExtensionSetup, public IADsExtension
  39. {
  40. private:
  41. IUnknown* m_pOuter;
  42. IDispatch* m_OuterDispatch;
  43. ITypeInfo* m_TypeInfo;
  44. IUnknown* m_pObject;
  45. BSTR m_ADSIPath;
  46. IBITSExtensionSetup* m_RemoteInterface;
  47. WCHAR * m_Path;
  48. bool m_InitComplete;
  49. CNonDelegatingIUnknown m_DelegationIUnknown;
  50. PropertyIDManager* m_PropertyMan;
  51. LONG m_Lock;
  52. HRESULT LoadPath();
  53. HRESULT ConnectToRemoteExtension();
  54. HRESULT LoadTypeInfo();
  55. public:
  56. CBITSExtensionSetup( IUnknown *Outer, IUnknown *Object );
  57. virtual ~CBITSExtensionSetup();
  58. IUnknown *GetNonDelegationIUknown()
  59. {
  60. return &m_DelegationIUnknown;
  61. }
  62. ///////////////////////////////
  63. // Interface IUnknown
  64. ///////////////////////////////
  65. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  66. STDMETHODIMP_(ULONG) AddRef();
  67. STDMETHODIMP_(ULONG) Release();
  68. // IADsExtension methods
  69. STDMETHOD(Operate)(ULONG dwCode, VARIANT varData1, VARIANT varData2, VARIANT varData3);
  70. STDMETHOD(PrivateGetIDsOfNames)(
  71. REFIID riid,
  72. OLECHAR FAR* FAR* rgszNames,
  73. unsigned int cNames,
  74. LCID lcid,
  75. DISPID FAR*
  76. rgDispId );
  77. STDMETHOD(PrivateGetTypeInfo)(
  78. unsigned int iTInfo,
  79. LCID lcid,
  80. ITypeInfo FAR* FAR* ppTInfo );
  81. STDMETHOD(PrivateGetTypeInfoCount)(
  82. unsigned int FAR* pctinfo );
  83. STDMETHOD(PrivateInvoke)(
  84. DISPID dispIdMember,
  85. REFIID riid, LCID lcid,
  86. WORD wFlags,
  87. DISPPARAMS FAR* pDispParams,
  88. VARIANT FAR* pVarResult,
  89. EXCEPINFO FAR* pExcepInfo,
  90. unsigned int FAR* puArgErr );
  91. // IDispatch Methods
  92. STDMETHOD(GetIDsOfNames)(
  93. REFIID riid,
  94. OLECHAR FAR* FAR* rgszNames,
  95. unsigned int cNames,
  96. LCID lcid,
  97. DISPID FAR*
  98. rgDispId );
  99. STDMETHOD(GetTypeInfo)(
  100. unsigned int iTInfo,
  101. LCID lcid,
  102. ITypeInfo FAR* FAR* ppTInfo );
  103. STDMETHOD(GetTypeInfoCount)(
  104. unsigned int FAR* pctinfo );
  105. STDMETHOD(Invoke)(
  106. DISPID dispIdMember,
  107. REFIID riid, LCID lcid,
  108. WORD wFlags,
  109. DISPPARAMS FAR* pDispParams,
  110. VARIANT FAR* pVarResult,
  111. EXCEPINFO FAR* pExcepInfo,
  112. unsigned int FAR* puArgErr );
  113. // IBITSExtensionSetup methods
  114. STDMETHODIMP EnableBITSUploads();
  115. STDMETHODIMP DisableBITSUploads();
  116. STDMETHODIMP GetCleanupTaskName( BSTR *pTaskName );
  117. STDMETHODIMP GetCleanupTask( REFIID riid, IUnknown **ppUnk );
  118. };
  119. class CBITSExtensionSetupFactory : public IBITSExtensionSetupFactory
  120. {
  121. long m_cref;
  122. ITypeInfo *m_TypeInfo;
  123. public:
  124. CBITSExtensionSetupFactory();
  125. virtual ~CBITSExtensionSetupFactory();
  126. HRESULT LoadTypeInfo();
  127. STDMETHODIMP GetObject( BSTR Path, IBITSExtensionSetup **ppExtensionSetup );
  128. ///////////////////////////////
  129. // Interface IUnknown
  130. ///////////////////////////////
  131. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  132. STDMETHODIMP_(ULONG) AddRef();
  133. STDMETHODIMP_(ULONG) Release();
  134. STDMETHOD(GetIDsOfNames)(
  135. REFIID riid,
  136. OLECHAR FAR* FAR* rgszNames,
  137. unsigned int cNames,
  138. LCID lcid,
  139. DISPID FAR*
  140. rgDispId );
  141. STDMETHOD(GetTypeInfo)(
  142. unsigned int iTInfo,
  143. LCID lcid,
  144. ITypeInfo FAR* FAR* ppTInfo );
  145. STDMETHOD(GetTypeInfoCount)(
  146. unsigned int FAR* pctinfo );
  147. STDMETHOD(Invoke)(
  148. DISPID dispIdMember,
  149. REFIID riid, LCID lcid,
  150. WORD wFlags,
  151. DISPPARAMS FAR* pDispParams,
  152. VARIANT FAR* pVarResult,
  153. EXCEPINFO FAR* pExcepInfo,
  154. unsigned int FAR* puArgErr );
  155. STDMETHODIMP EnableBITSUploads();
  156. STDMETHODIMP DisableBITSUploads();
  157. };
  158. class CPropSheetExtension : public IExtendPropertySheet
  159. {
  160. private:
  161. ULONG m_cref;
  162. // clipboard format
  163. static bool s_bStaticInitialized;
  164. static UINT s_cfDisplayName;
  165. static UINT s_cfSnapInCLSID;
  166. static UINT s_cfNodeType;
  167. static UINT s_cfSnapInMetapath;
  168. static UINT s_cfSnapInMachineName;
  169. static const UINT s_MaxUploadUnits[];
  170. static const UINT s_NumberOfMaxUploadUnits;
  171. static const UINT64 s_MaxUploadUnitsScales[];
  172. static const UINT s_NumberOfMaxUploadUnitsScales;
  173. static const UINT64 s_MaxUploadLimits[];
  174. static const UINT s_NumberOfMaxUploadLimits;
  175. static const UINT s_TimeoutUnits[];
  176. static const UINT s_NumberOfTimeoutUnits;
  177. static const DWORD s_TimeoutUnitsScales[];
  178. static const UINT s_NumberOfTimeoutUnitsScales;
  179. static const UINT64 s_TimeoutLimits[];
  180. static const UINT s_NumberOfTimeoutLimits;
  181. static const UINT s_NotificationTypes[];
  182. static const UINT s_NumberOfNotificationTypes;
  183. public:
  184. CPropSheetExtension();
  185. ~CPropSheetExtension();
  186. static HRESULT InitializeStatic();
  187. ///////////////////////////////
  188. // Interface IUnknown
  189. ///////////////////////////////
  190. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  191. STDMETHODIMP_(ULONG) AddRef();
  192. STDMETHODIMP_(ULONG) Release();
  193. ///////////////////////////////
  194. // Interface IExtendPropertySheet
  195. ///////////////////////////////
  196. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE CreatePropertyPages(
  197. /* [in] */ LPPROPERTYSHEETCALLBACK lpProvider,
  198. /* [in] */ LONG_PTR handle,
  199. /* [in] */ LPDATAOBJECT lpIDataObject);
  200. virtual /* [helpstring] */ HRESULT STDMETHODCALLTYPE QueryPagesFor(
  201. /* [in] */ LPDATAOBJECT lpDataObject);
  202. private:
  203. TCHAR * m_MetabasePath;
  204. TCHAR * m_MetabaseParent;
  205. TCHAR * m_ComputerName;
  206. TCHAR * m_UNCComputerName;
  207. GUID m_NodeGuid;
  208. IMSAdminBase* m_IISAdminBase;
  209. IBITSExtensionSetup* m_IBITSSetup;
  210. WCHAR m_NodeTypeName[MAX_PATH];
  211. PropertyIDManager* m_PropertyMan;
  212. HWND m_hwnd;
  213. bool m_SettingsChanged; // true if any settings changed
  214. bool m_EnabledSettingChanged; // true if the vdir was enabled or disabled
  215. struct InheritedValues
  216. {
  217. UINT64 MaxUploadSize;
  218. DWORD SessionTimeout;
  219. BITS_SERVER_NOTIFICATION_TYPE NotificationType;
  220. WCHAR * NotificationURL;
  221. WCHAR * HostId;
  222. DWORD FallbackTimeout;
  223. InheritedValues();
  224. ~InheritedValues();
  225. } m_InheritedValues;
  226. SmartITaskSchedulerPointer m_TaskSched;
  227. SmartITaskPointer m_CleanupTask;
  228. bool m_CleanupInProgress;
  229. FILETIME m_PrevCleanupStartTime;
  230. HCURSOR m_CleanupCursor;
  231. bool m_CleanupMinWaitTimerFired;
  232. static const UINT s_CleanupMinWaitTimerID = 1;
  233. static const UINT s_CleanupPollTimerID = 2;
  234. static const UINT s_CleanupMinWaitTimerInterval = 2000; // two seconds
  235. static const UINT s_CleanupPollTimerInterval = 1000; // one second
  236. static INT_PTR CALLBACK DialogProcExternal(
  237. HWND hwndDlg, // handle to dialog box
  238. UINT uMsg, // message
  239. WPARAM wParam, // first message parameter
  240. LPARAM lParam // second message parameter
  241. )
  242. {
  243. CPropSheetExtension *pThis;
  244. if ( WM_INITDIALOG == uMsg )
  245. {
  246. pThis = reinterpret_cast<CPropSheetExtension *>(reinterpret_cast<PROPSHEETPAGE *>(lParam)->lParam);
  247. SetWindowLongPtr( hwndDlg, DWLP_USER, reinterpret_cast<LONG_PTR>( pThis ) );
  248. }
  249. else
  250. {
  251. pThis = reinterpret_cast<CPropSheetExtension*>( GetWindowLongPtr( hwndDlg, DWLP_USER ) );
  252. }
  253. if ( !pThis )
  254. return FALSE;
  255. pThis->m_hwnd = hwndDlg;
  256. return pThis->DialogProc(
  257. uMsg,
  258. wParam,
  259. lParam );
  260. }
  261. INT_PTR DialogProc(
  262. UINT uMsg, // message
  263. WPARAM wParam, // first message parameter
  264. LPARAM lParam // second message parameter
  265. );
  266. HRESULT ComputeMetabaseParent();
  267. HRESULT ComputeUNCComputerName();
  268. HRESULT OpenSetupInterface();
  269. HRESULT LoadInheritedDWORD(
  270. METADATA_HANDLE mdHandle,
  271. WCHAR * pKeyName,
  272. DWORD PropId,
  273. DWORD * pReturn );
  274. HRESULT LoadInheritedString(
  275. METADATA_HANDLE mdHandle,
  276. WCHAR * pKeyName,
  277. DWORD PropId,
  278. WCHAR ** pReturn );
  279. void LoadInheritedValues( );
  280. void LoadValues( );
  281. void MergeError( HRESULT Hr, HRESULT * LastHr );
  282. HRESULT SaveSimpleString( METADATA_HANDLE mdHandle, DWORD PropId, DWORD EditId );
  283. HRESULT SaveTimeoutValue(
  284. METADATA_HANDLE mdHandle,
  285. DWORD PropId,
  286. DWORD CheckId,
  287. DWORD EditId,
  288. DWORD UnitId );
  289. void SetValues( );
  290. bool ValidateValues( );
  291. bool WarnAboutAccessFlags( );
  292. void AddComboBoxItems( UINT Combo, const UINT *Items, UINT NumberOfItems );
  293. void DisplayError( UINT StringId );
  294. void DisplayError( UINT StringId, HRESULT Hr );
  295. bool DisplayWarning( UINT StringId );
  296. void SetDlgItemTextAsInteger( UINT Id, UINT64 Value );
  297. bool GetDlgItemTextAsInteger( UINT Id, UINT MaxString, UINT64 & Value );
  298. void DisplayHelp( );
  299. void UpdateMaxUploadGroupState( bool IsEnabled );
  300. void UpdateTimeoutGroupState( bool IsEnabled );
  301. void UpdateNotificationsGroupState( bool IsEnabled );
  302. void UpdateConfigGroupState( bool IsEnabled );
  303. void UpdateServerFarmFallbackGroupState( bool IsEnabled );
  304. void UpdateServerFarmGroupState( bool IsEnabled );
  305. void UpdateUploadGroupState( );
  306. void UpdateCleanupState( );
  307. void CloseCleanupItems();
  308. void ScheduleCleanup();
  309. void CleanupNow();
  310. void CleanupTimer( UINT TimerID );
  311. void LoadMaxUploadValue( UINT64 MaxValue );
  312. void LoadTimeoutValue(
  313. DWORD CheckId,
  314. DWORD EditId,
  315. DWORD UnitId,
  316. DWORD Value );
  317. void LoadTimeoutValue( DWORD SessionTimeout );
  318. void LoadNotificationValues( BITS_SERVER_NOTIFICATION_TYPE NotificationType, WCHAR *NotificationURL );
  319. void LoadServerFarmSettings( WCHAR *HostId, DWORD FallbackTimeout );
  320. HRESULT ExtractData(
  321. IDataObject* piDataObject,
  322. CLIPFORMAT cfClipFormat,
  323. BYTE* pbData,
  324. DWORD cbData );
  325. HRESULT ExtractString( IDataObject *piDataObject,
  326. CLIPFORMAT cfClipFormat,
  327. _TCHAR *pstr,
  328. DWORD cchMaxLength)
  329. {
  330. return ExtractData( piDataObject, cfClipFormat, (PBYTE)pstr, cchMaxLength );
  331. }
  332. HRESULT ExtractSnapInCLSID( IDataObject* piDataObject, CLSID* pclsidSnapin )
  333. {
  334. return ExtractData( piDataObject, (CLIPFORMAT)s_cfSnapInCLSID, (PBYTE)pclsidSnapin, sizeof(CLSID) );
  335. }
  336. HRESULT ExtractObjectTypeGUID( IDataObject* piDataObject, GUID* pguidObjectType )
  337. {
  338. return ExtractData( piDataObject, (CLIPFORMAT)s_cfNodeType, (PBYTE)pguidObjectType, sizeof(GUID) );
  339. }
  340. HRESULT ExtractSnapInString( IDataObject * piDataObject,
  341. WCHAR * & String,
  342. UINT Format );
  343. HRESULT ExtractSnapInGUID( IDataObject * piDataObject,
  344. GUID & Guid,
  345. UINT Format );
  346. HRESULT SaveMetadataString(
  347. METADATA_HANDLE mdHandle,
  348. DWORD PropId,
  349. WCHAR *Value );
  350. HRESULT SaveMetadataDWORD(
  351. METADATA_HANDLE mdHandle,
  352. DWORD PropId,
  353. DWORD Value );
  354. };
  355. class CSnapinAbout : public ISnapinAbout
  356. {
  357. private:
  358. ULONG m_cref;
  359. HBITMAP m_hSmallImage;
  360. HBITMAP m_hLargeImage;
  361. HBITMAP m_hSmallImageOpen;
  362. HICON m_hAppIcon;
  363. public:
  364. CSnapinAbout();
  365. ~CSnapinAbout();
  366. ///////////////////////////////
  367. // Interface IUnknown
  368. ///////////////////////////////
  369. STDMETHODIMP QueryInterface(REFIID riid, LPVOID *ppv);
  370. STDMETHODIMP_(ULONG) AddRef();
  371. STDMETHODIMP_(ULONG) Release();
  372. ///////////////////////////////
  373. // Interface ISnapinAbout
  374. ///////////////////////////////
  375. STDMETHODIMP GetSnapinDescription(
  376. /* [out] */ LPOLESTR *lpDescription);
  377. STDMETHODIMP GetProvider(
  378. /* [out] */ LPOLESTR *lpName);
  379. STDMETHODIMP GetSnapinVersion(
  380. /* [out] */ LPOLESTR *lpVersion);
  381. STDMETHODIMP GetSnapinImage(
  382. /* [out] */ HICON *hAppIcon);
  383. STDMETHODIMP GetStaticFolderImage(
  384. /* [out] */ HBITMAP *hSmallImage,
  385. /* [out] */ HBITMAP *hSmallImageOpen,
  386. /* [out] */ HBITMAP *hLargeImage,
  387. /* [out] */ COLORREF *cMask);
  388. ///////////////////////////////
  389. // Private Interface
  390. ///////////////////////////////
  391. private:
  392. HRESULT LoadStringHelper(
  393. LPOLESTR *lpDest,
  394. UINT Id );
  395. };
  396. void
  397. ConnectToTaskScheduler(
  398. LPWSTR ComputerName,
  399. SmartITaskSchedulerPointer * TaskScheduler );
  400. void
  401. FindWorkItemForVDIR(
  402. SmartITaskSchedulerPointer TaskScheduler,
  403. LPCWSTR Key,
  404. SmartITaskPointer *ReturnedTask,
  405. LPWSTR *ReturnedTaskName );
  406. void
  407. IsBITSEnabledOnVDir(
  408. PropertyIDManager *PropertyManager,
  409. IMSAdminBase *IISAdminBase,
  410. LPWSTR VirtualDirectory,
  411. BOOL *IsEnabled );
  412. void
  413. EnableBITSForVDIR(
  414. PropertyIDManager *PropertyManager,
  415. SmartIMSAdminBasePointer IISAdminBase,
  416. LPCWSTR Path );
  417. void
  418. DisableBITSForVDIR(
  419. PropertyIDManager *PropertyManager,
  420. SmartIMSAdminBasePointer IISAdminBase,
  421. LPCWSTR Path,
  422. bool DisableForRollback,
  423. bool DisableForUpgrade );
  424. void CleanupForRemoval( LPCWSTR Path );
  425. #endif _BITSEXT_H_