Source code of Windows XP (NT5)
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.

1433 lines
36 KiB

  1. /*++
  2. Copyright (c) 1994-1998 Microsoft Corporation
  3. Module Name :
  4. inetprop.h
  5. Abstract:
  6. Internet Properties base classes definitions
  7. Author:
  8. Ronald Meijer (ronaldm)
  9. Project:
  10. Internet Services Manager
  11. Revision History:
  12. --*/
  13. #ifndef _INETPROP_H_
  14. #define _INETPROP_H_
  15. // Some useful macros to set edit control
  16. // and buddy spin control
  17. //
  18. #define SETUP_SPIN(s,min,max,pos)\
  19. (s).SetRange32((min),(max));\
  20. (s).SetPos((pos));\
  21. (s).SetAccel(3, toAcc)
  22. #define SETUP_EDIT_SPIN(f, e, s, min, max, pos)\
  23. (e).EnableWindow((f));\
  24. (s).EnableWindow((f));\
  25. SETUP_SPIN((s),(min),(max),(pos))
  26. //
  27. // InitializeAndFetch parameters
  28. //
  29. #define WITHOUT_INHERITANCE (FALSE)
  30. #define WITH_INHERITANCE (TRUE)
  31. //
  32. // SSL Port number to use if SSL is not enabled
  33. //
  34. #define SSL_NOT_ENABLED (0)
  35. //
  36. // Bandwidth and compression definitions
  37. //
  38. #define BANDWIDTH_MIN (1)
  39. #define BANDWIDTH_MAX (32767)
  40. #define INFINITE_BANDWIDTH (0xffffffff)
  41. #define KILOBYTE (1024L)
  42. #define MEGABYTE (1024L * KILOBYTE)
  43. #define DEF_BANDWIDTH (1 * MEGABYTE)
  44. #define DEF_MAX_COMPDIR_SIZE (1 * MEGABYTE)
  45. //
  46. // Private FILE_ATTRIBUTE used to designate a virtual directory
  47. //
  48. #define FILE_ATTRIBUTE_VIRTUAL_DIRECTORY (0x10000000)
  49. //
  50. // Attribute crackers
  51. //
  52. #define IS_VROOT(dwAttributes) ((dwAttributes & FILE_ATTRIBUTE_VIRTUAL_DIRECTORY) != 0)
  53. #define IS_DIR(dwAttributes) ((dwAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0)
  54. #define IS_FILE(dwAttributes) ((dwAttributes & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_VIRTUAL_DIRECTORY)) == 0)
  55. //
  56. // Metabase constants
  57. //
  58. //
  59. // TODO: From mdkeys?
  60. //
  61. extern const LPCTSTR g_cszTemplates;
  62. extern const LPCTSTR g_cszCompression;
  63. extern const LPCTSTR g_cszMachine;
  64. extern const LPCTSTR g_cszMimeMap;
  65. extern const LPCTSTR g_cszRoot;
  66. extern const LPCTSTR g_cszSep;
  67. extern const TCHAR g_chSep;
  68. //
  69. // Utility Functions
  70. //
  71. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  72. //
  73. // Forward Definitions
  74. //
  75. class CIPAddress;
  76. //
  77. // Determine if the currently logged-in user us an administrator
  78. // or operator in the virtual server provided
  79. //
  80. HRESULT
  81. DetermineIfAdministrator(
  82. IN CMetaInterface * pInterface,
  83. IN LPCTSTR lpszMetabasePath,
  84. OUT BOOL * pfAdministrator
  85. );
  86. //
  87. // Utility classes
  88. //
  89. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  90. class CMaskedDWORD
  91. /*++
  92. Class Description:
  93. A masked DWORD class. This class performs assignments and comparison
  94. on a masked range of the DWORD value. For example, if a mask of
  95. 0x000000FF is set, any comparisons or assignments will only involve
  96. the least significant byte. A comparison against another DWORD will
  97. only compare that least significant byte, and an assignment will only
  98. set the least significant byte, leaving the rest untouched.
  99. Public Interface:
  100. CMaskedDWORD : Constructor
  101. operator == : Comparison operator
  102. operator != : Comparison operator
  103. operator = : Assignment operator
  104. operator DWORD : Cast to the value
  105. void SetMask : Set the mask
  106. --*/
  107. {
  108. //
  109. // Constructor/Destructor
  110. //
  111. public:
  112. CMaskedDWORD(
  113. IN DWORD dwValue = 0L,
  114. IN DWORD dwMask = 0xFFFFFFFF
  115. )
  116. : m_dwValue(dwValue),
  117. m_dwMask(dwMask)
  118. {
  119. }
  120. public:
  121. BOOL operator ==(DWORD dwValue) const;
  122. BOOL operator !=(DWORD dwValue) const { return !(operator ==(dwValue)); }
  123. CMaskedDWORD & operator =(DWORD dwValue);
  124. operator DWORD() const { return m_dwValue; }
  125. operator DWORD &() { return m_dwValue; }
  126. void SetMask(DWORD dwMask) { m_dwMask = dwMask; }
  127. private:
  128. DWORD m_dwValue;
  129. DWORD m_dwMask;
  130. };
  131. //
  132. // Forward Definitions
  133. //
  134. class CIPAddress;
  135. template <class TYPE, class ARG_TYPE>
  136. class CMPProp
  137. {
  138. public:
  139. CMPProp(ARG_TYPE value);
  140. CMPProp();
  141. operator ARG_TYPE() const;
  142. CMPProp<TYPE, ARG_TYPE> & operator =(ARG_TYPE value);
  143. BOOL m_fDirty;
  144. TYPE m_value;
  145. };
  146. template <class TYPE, class ARG_TYPE>
  147. inline CMPProp<TYPE, ARG_TYPE>::CMPProp(ARG_TYPE value)
  148. : m_value(value),
  149. m_fDirty(FALSE)
  150. {
  151. }
  152. template <class TYPE, class ARG_TYPE>
  153. inline CMPProp<TYPE, ARG_TYPE>::CMPProp()
  154. : m_value(),
  155. m_fDirty(FALSE)
  156. {
  157. }
  158. template <class TYPE, class ARG_TYPE>
  159. inline CMPProp<TYPE, ARG_TYPE>::operator ARG_TYPE() const
  160. {
  161. return (ARG_TYPE)m_value;
  162. }
  163. template <class TYPE, class ARG_TYPE>
  164. inline CMPProp<TYPE, ARG_TYPE> & CMPProp<TYPE, ARG_TYPE>::operator =(ARG_TYPE value)
  165. {
  166. if (m_value != value)
  167. {
  168. m_value = value;
  169. m_fDirty = TRUE;
  170. }
  171. return *this;
  172. }
  173. //
  174. // MP Access (use operators where possible!)
  175. //
  176. #define MP_V(x) (x.m_value)
  177. #define MP_D(x) (x.m_fDirty)
  178. //
  179. // Common property types
  180. //
  181. typedef CMPProp<CBlob, CBlob&> MP_CBlob;
  182. typedef CMPProp<CString, LPCTSTR> MP_CString;
  183. typedef CMPProp<CStringListEx, CStringListEx &> MP_CStringListEx;
  184. typedef CMPProp<CILong, LONG> MP_CILong;
  185. typedef CMPProp<int, int> MP_int;
  186. typedef CMPProp<DWORD, DWORD> MP_DWORD;
  187. typedef CMPProp<BOOL, BOOL> MP_BOOL;
  188. typedef CMPProp<CMaskedDWORD, DWORD> MP_CMaskedDWORD;
  189. //
  190. // CODEWORK: Turns these into proper methods
  191. //
  192. #define BEGIN_META_WRITE()\
  193. { \
  194. HRESULT hr = S_OK; \
  195. do \
  196. { \
  197. m_dwaDirtyProps.RemoveAll(); \
  198. #define META_WRITE(id, value)\
  199. if(MP_D(value)) \
  200. { \
  201. if (!IsOpen()) \
  202. { \
  203. hr = OpenForWriting(); \
  204. if (FAILED(hr)) break; \
  205. } \
  206. hr = SetValue(id, MP_V(value)); \
  207. if (FAILED(hr)) break; \
  208. MP_D(value) = FALSE; \
  209. m_dwaDirtyProps.AddTail(id); \
  210. } \
  211. #define META_WRITE_INHERITANCE(id, value, foverride)\
  212. if(MP_D(value)) \
  213. { \
  214. if (!IsOpen()) \
  215. { \
  216. hr = OpenForWriting(); \
  217. if (FAILED(hr)) break; \
  218. } \
  219. hr = SetValue(id, MP_V(value), &foverride);\
  220. if (FAILED(hr)) break; \
  221. MP_D(value) = FALSE; \
  222. m_dwaDirtyProps.AddTail(id); \
  223. } \
  224. #define META_DELETE(id)\
  225. FlagPropertyForDeletion(id); \
  226. #define END_META_WRITE(err)\
  227. POSITION pos; \
  228. pos = m_dwaDeletedProps.GetHeadPosition();\
  229. while(pos != NULL) \
  230. { \
  231. DWORD dwID = m_dwaDeletedProps.GetNext(pos);\
  232. if (!IsOpen()) \
  233. { \
  234. hr = OpenForWriting(FALSE); \
  235. if (SUCCEEDED(hr)) \
  236. { \
  237. TRACEEOLID("Deleting #" << dwID);\
  238. hr = DeleteValue(dwID); \
  239. m_dwaDirtyProps.AddTail(dwID); \
  240. } \
  241. } \
  242. } \
  243. m_dwaDeletedProps.RemoveAll(); \
  244. if (IsOpen()) Close(); \
  245. pos = m_dwaDirtyProps.GetHeadPosition();\
  246. hr = S_OK; \
  247. while(pos != NULL) \
  248. { \
  249. hr = CheckDescendants(m_dwaDirtyProps.GetNext(pos), &m_auth, m_strMetaRoot); \
  250. if (FAILED(hr)) break; \
  251. } \
  252. } \
  253. while(FALSE); \
  254. err = hr; \
  255. }
  256. /* ABSTRACT */ class CMetaProperties : public CMetaKey
  257. /*++
  258. Class Description:
  259. Abstract base class that reads all metadata at a specific
  260. metabase path.
  261. Public Interface:
  262. QueryResult : Get result code from construction
  263. QueryMetaPath : Get the metabase path
  264. Virtual Interface:
  265. ParseFields : Break up data into member variables
  266. --*/
  267. {
  268. //
  269. // Constructor/Destructor
  270. //
  271. protected:
  272. //
  273. // Constructor which creates new interface
  274. //
  275. CMetaProperties(
  276. IN CComAuthInfo * pAuthInfo,
  277. IN LPCTSTR lpszMDPath
  278. );
  279. //
  280. // Construct with existing interface
  281. //
  282. CMetaProperties(
  283. IN CMetaInterface * pInterface,
  284. IN LPCTSTR lpszMDPath
  285. );
  286. //
  287. // Construct with open key
  288. //
  289. CMetaProperties(
  290. IN CMetaKey * pKey,
  291. IN LPCTSTR lpszMDPath
  292. );
  293. //
  294. // Destructor
  295. //
  296. ~CMetaProperties();
  297. public:
  298. //
  299. // GetAllData()
  300. //
  301. virtual HRESULT LoadData();
  302. virtual HRESULT WriteDirtyProps();
  303. void FlagPropertyForDeletion(DWORD dwID);
  304. virtual HRESULT CMetaProperties::QueryResult() const;
  305. LPCTSTR QueryMetaRoot() const { return m_strMetaRoot; }
  306. protected:
  307. virtual void ParseFields() = 0;
  308. void Cleanup();
  309. HRESULT OpenForWriting(BOOL fCreate = TRUE);
  310. protected:
  311. BOOL m_fInherit;
  312. HRESULT m_hResult;
  313. CString m_strMetaRoot;
  314. DWORD m_dwMDUserType;
  315. DWORD m_dwMDDataType;
  316. CList<DWORD, DWORD> m_dwaDirtyProps;
  317. CList<DWORD, DWORD> m_dwaDeletedProps;
  318. //
  319. // Read all values
  320. //
  321. DWORD m_dwNumEntries;
  322. DWORD m_dwMDDataLen;
  323. PBYTE m_pbMDData;
  324. };
  325. //
  326. // Machine Properties object
  327. //
  328. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  329. class CMachineProps : public CMetaProperties
  330. /*++
  331. Class Description:
  332. Global machine properties
  333. Public Interface:
  334. CMachineProps : Constructor
  335. WriteDirtyProps : Write dirty properties
  336. --*/
  337. {
  338. public:
  339. CMachineProps(CComAuthInfo * pAuthInfo);
  340. CMachineProps(CMetaInterface * pInterface);
  341. public:
  342. HRESULT WriteDirtyProps();
  343. protected:
  344. virtual void ParseFields();
  345. public:
  346. MP_BOOL m_fEnableMetabaseEdit;
  347. };
  348. //
  349. // Compression Properties Object
  350. //
  351. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  352. class CIISCompressionProps : public CMetaProperties
  353. /*++
  354. Class Description:
  355. Compression settings
  356. Public Interface:
  357. CIISCompressionProps : Constructor
  358. WriteIfDirty : Write data if dirty
  359. --*/
  360. {
  361. public:
  362. CIISCompressionProps(
  363. IN CComAuthInfo * pAuthInfo
  364. );
  365. public:
  366. //
  367. // Write Data if dirty
  368. //
  369. virtual HRESULT WriteDirtyProps();
  370. //
  371. // Load data
  372. //
  373. virtual HRESULT LoadData();
  374. public:
  375. MP_BOOL m_fEnableStaticCompression;
  376. MP_BOOL m_fEnableDynamicCompression;
  377. MP_BOOL m_fLimitDirectorySize;
  378. MP_DWORD m_dwDirectorySize;
  379. MP_CString m_strDirectory;
  380. protected:
  381. virtual void ParseFields();
  382. private:
  383. BOOL m_fPathDoesNotExist;
  384. };
  385. class CMimeTypes : public CMetaProperties
  386. /*++
  387. Class Description:
  388. A list of mime types.
  389. Public Interface:
  390. CMimeTypes : Constructor
  391. WriteIfDirty : Write properties if dirty
  392. --*/
  393. {
  394. public:
  395. //
  396. // Constructor that creates new interface
  397. //
  398. CMimeTypes(
  399. IN CComAuthInfo * pAuthInfo,
  400. IN LPCTSTR lpszMDPath
  401. );
  402. //
  403. // Constructor that uses an existing interface
  404. //
  405. CMimeTypes(
  406. IN CMetaInterface * pInterface,
  407. IN LPCTSTR lpszMDPath
  408. );
  409. public:
  410. //
  411. // Write the data;
  412. //
  413. virtual HRESULT WriteDirtyProps();
  414. protected:
  415. virtual void ParseFields();
  416. public:
  417. MP_CStringListEx m_strlMimeTypes;
  418. };
  419. class CServerCapabilities : public CMetaProperties
  420. /*++
  421. Class Description:
  422. Server capabilities object
  423. Public Interface:
  424. CServerCapabilities : Constructor
  425. --*/
  426. {
  427. public:
  428. //
  429. // Constructor that creates a new interface
  430. //
  431. CServerCapabilities(
  432. IN CComAuthInfo * pAuthInfo,
  433. IN LPCTSTR lpszMDPath // e.g. "lm/w3svc/info"
  434. );
  435. //
  436. // Constructor that uses an existing interface
  437. //
  438. CServerCapabilities(
  439. IN CMetaInterface * pInterface,
  440. IN LPCTSTR lpszMDPath // e.g. "lm/w3svc/info"
  441. );
  442. public:
  443. BOOL IsSSLSupported() const { return (m_dwCapabilities & IIS_CAP1_SSL_SUPPORT) != 0L; }
  444. BOOL IsSSL128Supported() const
  445. {
  446. if (m_dwVersionMajor >= 6)
  447. {
  448. // We have this feature ALWAYS enabled in iis6 and iis5.1
  449. return TRUE;
  450. }
  451. else if (m_dwVersionMajor == 5 && m_dwVersionMinor == 1)
  452. {
  453. return TRUE;
  454. }
  455. else
  456. {
  457. return (m_dwConfiguration & MD_SERVER_CONFIG_SSL_128) != 0L;
  458. }
  459. }
  460. BOOL HasMultipleSites() const { return (m_dwCapabilities & IIS_CAP1_MULTIPLE_INSTANCE) != 0L; }
  461. BOOL HasBwThrottling() const { return (m_dwCapabilities & IIS_CAP1_BW_THROTTLING) != 0L; }
  462. BOOL Has10ConnectionLimit() const { return (m_dwCapabilities & IIS_CAP1_10_CONNECTION_LIMIT) != 0L; }
  463. BOOL HasIPAccessCheck() const { return (m_dwCapabilities & IIS_CAP1_IP_ACCESS_CHECK) != 0L; }
  464. BOOL HasOperatorList() const { return (m_dwCapabilities & IIS_CAP1_OPERATORS_LIST) != 0L; }
  465. BOOL HasFrontPage() const { return (m_dwCapabilities & IIS_CAP1_FP_INSTALLED) != 0L; }
  466. BOOL HasCompression() const { return (m_dwCapabilities & IIS_CAP1_SERVER_COMPRESSION) != 0L; }
  467. BOOL HasCPUThrottling() const { return (m_dwCapabilities & IIS_CAP1_CPU_AUDITING) != 0L; }
  468. BOOL HasDAV() const { return (m_dwCapabilities & IIS_CAP1_DAV) != 0L; }
  469. BOOL HasDigest() const { return (m_dwCapabilities & IIS_CAP1_DIGEST_SUPPORT) != 0L; }
  470. BOOL HasNTCertMapper() const { return (m_dwCapabilities & IIS_CAP1_NT_CERTMAP_SUPPORT) != 0L; }
  471. DWORD QueryMajorVersion() const { return m_dwVersionMajor; }
  472. DWORD QueryMinorVersion() const { return m_dwVersionMinor; }
  473. protected:
  474. virtual void ParseFields();
  475. private:
  476. //
  477. // Capabilities fields
  478. //
  479. MP_DWORD m_dwPlatform;
  480. MP_DWORD m_dwVersionMajor;
  481. MP_DWORD m_dwVersionMinor;
  482. MP_DWORD m_dwCapabilities;
  483. MP_DWORD m_dwConfiguration;
  484. };
  485. class CInstanceProps : public CMetaProperties
  486. /*++
  487. Class Description:
  488. Generic instance properties. Construct with lightweight = TRUE
  489. to fetch enough information for enumeration only.
  490. Public Interface:
  491. CInstanceProps: : Constructor
  492. Add : static method to create new instance
  493. Remove : static method to remove instance
  494. ChangeState : Change the state of a property
  495. QueryError : Get the win32 error
  496. GetDisplayText : Generate display name of instance
  497. --*/
  498. {
  499. public:
  500. //
  501. // Public method to convert instance info to display text
  502. //
  503. static LPCTSTR GetDisplayText(
  504. OUT CString & strName,
  505. IN LPCTSTR szComment,
  506. IN LPCTSTR szHostHeaderName,
  507. //IN LPCTSTR szServiceName,
  508. IN CIPAddress & ia,
  509. IN UINT uPort,
  510. IN DWORD dwID
  511. );
  512. public:
  513. //
  514. // Constructor that creates an interface
  515. //
  516. CInstanceProps(
  517. IN CComAuthInfo * pAuthInfo,
  518. IN LPCTSTR lpszMDPath,
  519. IN UINT nDefPort = 0U
  520. );
  521. //
  522. // Constructor that reuses existing interface
  523. //
  524. CInstanceProps(
  525. IN CMetaInterface * pInterface,
  526. IN LPCTSTR lpszMDPath,
  527. IN UINT nDefPort = 0U
  528. );
  529. //
  530. // Special constructor that uses an open parent key,
  531. // and uses a relative path off the open key.
  532. //
  533. CInstanceProps(
  534. IN CMetaKey * pKey,
  535. IN LPCTSTR lpszMDPath,
  536. IN DWORD dwInstance,
  537. IN UINT nDefPort = 0U
  538. );
  539. public:
  540. //
  541. // Parse the binding string into component parts
  542. //
  543. static void CrackBinding(
  544. IN CString lpszBinding,
  545. OUT CIPAddress & iaIpAddress,
  546. OUT UINT & nTCPPort,
  547. OUT CString & strDomainName
  548. );
  549. //
  550. // Parse the secure binding string into component parts
  551. //
  552. static void CrackSecureBinding(
  553. IN CString lpszBinding,
  554. OUT CIPAddress & iaIpAddress,
  555. OUT UINT & nSSLPort
  556. );
  557. //
  558. // Find the SSL port applicable to the given
  559. // IP Address. Return the index where this SSL port
  560. // was found, or -1 if it was not found.
  561. //
  562. static int FindMatchingSecurePort(
  563. IN CStringList & strlBindings,
  564. IN CIPAddress & iaIpAddress,
  565. OUT UINT & m_nSSLPort
  566. );
  567. //
  568. // Find ip address/port combo
  569. //
  570. static BOOL IsPortInUse(
  571. IN CStringList & strlBindings,
  572. IN CIPAddress & iaIPAddress,
  573. IN UINT nPort
  574. );
  575. //
  576. // Build binding string
  577. //
  578. static void BuildBinding(
  579. OUT CString & strBinding,
  580. IN CIPAddress & iaIpAddress,
  581. IN UINT & nTCPPort,
  582. IN CString & lpszDomainName
  583. );
  584. //
  585. // Build secure binding string
  586. //
  587. static void BuildSecureBinding(
  588. OUT CString & strBinding,
  589. IN CIPAddress & iaIpAddress,
  590. IN UINT & nSSLPort
  591. );
  592. //
  593. // Create new instance
  594. //
  595. static HRESULT Add(
  596. IN CMetaInterface * pInterface,
  597. IN LPCTSTR lpszService,
  598. IN LPCTSTR lpszHomePath,
  599. IN LPCTSTR lpszUserName = NULL,
  600. IN LPCTSTR lpszPassword = NULL,
  601. IN LPCTSTR lpszDescription = NULL,
  602. IN LPCTSTR lpszBinding = NULL,
  603. IN LPCTSTR lpszSecureBinding = NULL,
  604. IN DWORD * pdwPermissions = NULL,
  605. IN DWORD * pdwDirBrowsing = NULL,
  606. IN DWORD * pwdAuthFlags = NULL,
  607. OUT DWORD * pdwInstance = NULL
  608. );
  609. //
  610. // Remove existing instance
  611. //
  612. static HRESULT Delete(
  613. IN CMetaInterface * pInterface,
  614. IN LPCTSTR lpszService,
  615. IN DWORD dwInstance
  616. );
  617. //
  618. // Access
  619. //
  620. public:
  621. //
  622. // Change the running state of the instance
  623. //
  624. HRESULT ChangeState(
  625. IN DWORD dwCommand
  626. );
  627. //
  628. // Get the WIN32 error
  629. //
  630. DWORD QueryError() const { return m_dwWin32Error; }
  631. //
  632. // Get the instance number
  633. //
  634. DWORD QueryInstance() const { return m_dwInstance; }
  635. //
  636. // Check to see if this is a deletable instance
  637. //
  638. BOOL IsDeletable() const { return !m_fNotDeletable; }
  639. //
  640. // Check to see if this is a cluster enabled instance
  641. //
  642. BOOL IsClusterEnabled() const { return m_fCluster; }
  643. //
  644. // Get the friendly name for this instance
  645. //
  646. LPCTSTR GetDisplayText(
  647. OUT CString & strName
  648. //IN LPCTSTR szServiceName
  649. );
  650. //
  651. // Get the complete metabase path to the home directory
  652. //
  653. LPCTSTR GetHomePath(OUT CString & str);
  654. //
  655. // Write Data if dirty
  656. //
  657. virtual HRESULT WriteDirtyProps();
  658. protected:
  659. virtual void ParseFields();
  660. public:
  661. //
  662. // Meta values
  663. //
  664. MP_BOOL m_fNotDeletable;
  665. MP_BOOL m_fCluster;
  666. MP_CStringListEx m_strlBindings;
  667. MP_CString m_strComment;
  668. MP_DWORD m_dwState;
  669. MP_DWORD m_dwWin32Error;
  670. //
  671. // Derived Values
  672. //
  673. UINT m_nTCPPort;
  674. CIPAddress m_iaIpAddress;
  675. CString m_strDomainName;
  676. private:
  677. DWORD m_dwInstance;
  678. };
  679. class CChildNodeProps : public CMetaProperties
  680. /*++
  681. Class Description:
  682. Generic child node properties. Could be a vdir, a dir
  683. or a file.
  684. Public Interface:
  685. CChildNodeProps : Constructor
  686. Add : Create new virtual directory
  687. Delete : Delete virtual directory
  688. Rename : Rename virtual directory
  689. QueryError : Get the win32 error
  690. IsPathInherited : Return TRUE if the path was inherited
  691. FillInstanceInfo : Fill instance info structure
  692. FillChildInfo : Fill child info structure
  693. --*/
  694. {
  695. public:
  696. //
  697. // Constructors
  698. //
  699. CChildNodeProps(
  700. IN CComAuthInfo * pAuthInfo,
  701. IN LPCTSTR lpszMDPath,
  702. IN BOOL fInherit = WITHOUT_INHERITANCE,
  703. IN BOOL fPathOnly = FALSE
  704. );
  705. CChildNodeProps(
  706. IN CMetaInterface * pInterface,
  707. IN LPCTSTR lpszMDPath,
  708. IN BOOL fInherit = WITHOUT_INHERITANCE,
  709. IN BOOL fPathOnly = FALSE
  710. );
  711. CChildNodeProps(
  712. IN CMetaKey * pKey,
  713. IN LPCTSTR lpszPath = NULL,
  714. IN BOOL fInherit = WITHOUT_INHERITANCE,
  715. IN BOOL fPathOnly = FALSE
  716. );
  717. public:
  718. //
  719. // Create new virtual directory
  720. //
  721. static HRESULT Add(
  722. IN CMetaInterface * pInterface,
  723. IN LPCTSTR lpszParentPath,
  724. /*
  725. IN LPCTSTR lpszService,
  726. IN DWORD dwInstance,
  727. IN LPCTSTR lpszParentPath,
  728. */
  729. IN LPCTSTR lpszAlias,
  730. OUT CString & strAliasCreated,
  731. IN DWORD * pdwPermissions = NULL,
  732. IN DWORD * pdwDirBrowsing = NULL,
  733. IN LPCTSTR lpszVrPath = NULL,
  734. IN LPCTSTR lpszUserName = NULL,
  735. IN LPCTSTR lpszPassword = NULL,
  736. IN BOOL fExactName = TRUE
  737. );
  738. //
  739. // Delete virtual directory
  740. //
  741. static HRESULT Delete(
  742. IN CMetaInterface * pInterface,
  743. IN LPCTSTR lpszParentPath, OPTIONAL
  744. IN LPCTSTR lpszNode
  745. );
  746. //
  747. // Rename virtual directory
  748. //
  749. static HRESULT Rename(
  750. IN CMetaInterface * pInterface,
  751. IN LPCTSTR lpszParentPath, OPTIONAL
  752. IN LPCTSTR lpszOldName,
  753. IN LPCTSTR lpszNewName
  754. );
  755. public:
  756. //
  757. // TRUE, if this is an enabled application
  758. //
  759. BOOL IsEnabledApplication() { return m_fIsAppRoot; }
  760. //
  761. // Get the alias name
  762. //
  763. LPCTSTR QueryAlias() const { return m_strAlias; }
  764. //CString & GetAlias() { return m_strAlias; }
  765. //
  766. // Get the error
  767. //
  768. DWORD QueryWin32Error() const { return m_dwWin32Error; }
  769. //
  770. // This is how to separate file/dir props from vdirs
  771. //
  772. BOOL IsPathInherited() const { return m_fPathInherited; }
  773. //
  774. // Empty the path if it was inherited
  775. //
  776. void RemovePathIfInherited();
  777. //
  778. // CODEWORK: Ugly solution.
  779. //
  780. // Call this method to override the inheritance status of the
  781. // http redirect path
  782. //
  783. void MarkRedirAsInherit(BOOL fInherit) { m_fInheritRedirect = fInherit; }
  784. //
  785. // Get the path
  786. //
  787. CString & GetPath() { return MP_V(m_strPath); }
  788. //
  789. // Get the redirected path
  790. //
  791. CString & GetRedirectedPath() { return m_strRedirectPath; }
  792. //
  793. // Get the access perms
  794. //
  795. DWORD QueryAccessPerms() const { return m_dwAccessPerms; }
  796. //
  797. // Get dir browsing bits
  798. //
  799. DWORD QueryDirBrowsing() const { return m_dwDirBrowsing; }
  800. //
  801. // True if the child is redirected
  802. //
  803. BOOL IsRedirected() const { return !m_strRedirectPath.IsEmpty(); }
  804. //
  805. // Write Data if dirty
  806. //
  807. virtual HRESULT WriteDirtyProps();
  808. protected:
  809. //
  810. // Break out GetAllData() data to data fields
  811. //
  812. virtual void ParseFields();
  813. //
  814. // Break down redirect statement into component paths
  815. //
  816. void ParseRedirectStatement();
  817. //
  818. // Reverse the above -- reassemble the redirect statement
  819. //
  820. void BuildRedirectStatement();
  821. protected:
  822. //
  823. // Redirect tags
  824. //
  825. static const TCHAR _chTagSep;
  826. static const LPCTSTR _cszExactDestination;
  827. static const LPCTSTR _cszChildOnly;
  828. static const LPCTSTR _cszPermanent;
  829. public:
  830. BOOL m_fIsAppRoot;
  831. BOOL m_fPathInherited;
  832. BOOL m_fInheritRedirect;
  833. BOOL m_fExact; // Redirect tag
  834. BOOL m_fChild; // Redirect tag
  835. BOOL m_fPermanent; // Redirect tag
  836. CString m_strAlias;
  837. CString m_strFullMetaPath;
  838. CString m_strRedirectPath; // Redirect _path_
  839. public:
  840. MP_BOOL m_fAppIsolated;
  841. MP_DWORD m_dwWin32Error;
  842. MP_DWORD m_dwDirBrowsing;
  843. MP_CString m_strPath;
  844. MP_CString m_strRedirectStatement; // Path + tags
  845. MP_CString m_strAppRoot;
  846. MP_CMaskedDWORD m_dwAccessPerms;
  847. };
  848. inline CMetaKey * GetMetaKeyFromHandle(IN HANDLE hServer)
  849. {
  850. ASSERT(hServer != NULL);
  851. return (CMetaKey *)hServer;
  852. }
  853. inline LPCTSTR GetServerNameFromHandle(IN HANDLE hServer)
  854. {
  855. ASSERT(hServer != NULL);
  856. return ((CMetaKey *)hServer)->QueryServerName();
  857. }
  858. //
  859. // Metabase Helpers
  860. //
  861. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  862. //
  863. // Get record data size
  864. //
  865. inline DWORD RecordDataSize(
  866. IN METADATA_GETALL_RECORD * pAllRecord,
  867. IN int iIndex
  868. )
  869. {
  870. return pAllRecord[iIndex].dwMDDataLen;
  871. }
  872. //
  873. // Fetch data at index as DWORD
  874. //
  875. inline void FetchMetaValue(
  876. IN METADATA_GETALL_RECORD * pAllRecord,
  877. IN int iIndex,
  878. OUT DWORD & dwValue
  879. )
  880. {
  881. ASSERT(RecordDataSize(pAllRecord, iIndex) == sizeof(DWORD));
  882. dwValue = *((UNALIGNED DWORD *)((PBYTE)pAllRecord + pAllRecord[iIndex].dwMDDataOffset));
  883. }
  884. //
  885. // Fetch data at index as UINT
  886. //
  887. inline void FetchMetaValue(
  888. IN METADATA_GETALL_RECORD * pAllRecord,
  889. IN int iIndex,
  890. OUT UINT & uValue
  891. )
  892. {
  893. ASSERT(RecordDataSize(pAllRecord, iIndex) == sizeof(DWORD));
  894. uValue = (UINT)*((UNALIGNED DWORD *)((PBYTE)pAllRecord + pAllRecord[iIndex].dwMDDataOffset));
  895. }
  896. //
  897. // Fetch data at index as int
  898. //
  899. inline void FetchMetaValue(
  900. IN METADATA_GETALL_RECORD * pAllRecord,
  901. IN int iIndex,
  902. OUT int & iValue
  903. )
  904. {
  905. ASSERT(RecordDataSize(pAllRecord, iIndex) == sizeof(DWORD));
  906. iValue = (int)*((UNALIGNED DWORD *)((PBYTE)pAllRecord + pAllRecord[iIndex].dwMDDataOffset));
  907. }
  908. //
  909. // Fetch data at index as a CString
  910. //
  911. inline void FetchMetaValue(
  912. IN METADATA_GETALL_RECORD * pAllRecord,
  913. IN int iIndex,
  914. OUT CString & strValue
  915. )
  916. {
  917. strValue = (LPTSTR)((PBYTE)pAllRecord + pAllRecord[iIndex].dwMDDataOffset);
  918. }
  919. //
  920. // Fetch data at index as a CStringList
  921. //
  922. inline void FetchMetaValue(
  923. IN METADATA_GETALL_RECORD * pAllRecord,
  924. IN int iIndex,
  925. OUT CStringList & strlValue
  926. )
  927. {
  928. ConvertDoubleNullListToStringList(
  929. ((LPCTSTR)((PBYTE)pAllRecord + pAllRecord[iIndex].dwMDDataOffset)),
  930. strlValue,
  931. (RecordDataSize(pAllRecord, iIndex)) / sizeof(TCHAR)
  932. );
  933. }
  934. //
  935. // Fetch binary data as a blob
  936. //
  937. inline void FetchMetaValue(
  938. IN METADATA_GETALL_RECORD * pAllRecord,
  939. IN int iIndex,
  940. OUT CBlob & blob
  941. )
  942. {
  943. blob.SetValue(
  944. RecordDataSize(pAllRecord, iIndex),
  945. ((PBYTE)pAllRecord + pAllRecord[iIndex].dwMDDataOffset));
  946. }
  947. inline void FetchMetaValue(
  948. IN METADATA_GETALL_RECORD * pAllRecord,
  949. IN int iIndex,
  950. OUT CILong & ilValue
  951. )
  952. {
  953. ilValue = (LONG)*((UNALIGNED DWORD *)((PBYTE)pAllRecord + pAllRecord[iIndex].dwMDDataOffset));
  954. }
  955. //
  956. // Fetch data at index as CString, and check inheritance status
  957. //
  958. inline void FetchInheritedMetaValue(
  959. IN METADATA_GETALL_RECORD * pAllRecord,
  960. IN int iIndex,
  961. OUT CString & strValue,
  962. OUT BOOL & fIsInherited
  963. )
  964. {
  965. strValue = (LPTSTR)((PBYTE)pAllRecord + pAllRecord[iIndex].dwMDDataOffset);
  966. fIsInherited = (pAllRecord[iIndex].dwMDAttributes & METADATA_ISINHERITED) != 0;
  967. }
  968. //
  969. // Flag Operations
  970. //
  971. #define IS_FLAG_SET(dw, flag) ((((dw) & (flag)) != 0) ? TRUE : FALSE)
  972. #define SET_FLAG(dw, flag) dw |= (flag)
  973. #define RESET_FLAG(dw, flag) dw &= ~(flag)
  974. #define SET_FLAG_IF(cond, dw, flag)\
  975. if (cond) \
  976. { \
  977. SET_FLAG(dw, flag); \
  978. } \
  979. else \
  980. { \
  981. RESET_FLAG(dw, flag); \
  982. }
  983. //
  984. // Meta record crackers
  985. //
  986. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  987. #define BEGIN_PARSE_META_RECORDS(dwNumEntries, pbMDData)\
  988. { \
  989. METADATA_GETALL_RECORD * pAllRecords = \
  990. (METADATA_GETALL_RECORD *)pbMDData; \
  991. ASSERT(pAllRecords != NULL); \
  992. \
  993. for (DWORD i = 0; i < dwNumEntries; ++i) \
  994. { \
  995. METADATA_GETALL_RECORD * pRec = &pAllRecords[i];\
  996. switch(pRec->dwMDIdentifier) \
  997. {
  998. #define HANDLE_META_RECORD(id, value)\
  999. case id: \
  1000. FetchMetaValue(pAllRecords, i, MP_V(value));\
  1001. break;
  1002. #define HANDLE_INHERITED_META_RECORD(id, value, fIsInherited)\
  1003. case id: \
  1004. FetchInheritedMetaValue(pAllRecords, i, MP_V(value), fIsInherited);\
  1005. break;
  1006. #define END_PARSE_META_RECORDS\
  1007. } \
  1008. } \
  1009. }
  1010. //
  1011. // Sheet -> page crackers
  1012. //
  1013. #define BEGIN_META_INST_READ(sheet)\
  1014. { \
  1015. sheet * pSheet = (sheet *)GetSheet(); \
  1016. do \
  1017. { \
  1018. if (FAILED(pSheet->QueryInstanceResult())) \
  1019. { \
  1020. break; \
  1021. }
  1022. #define FETCH_INST_DATA_FROM_SHEET(value)\
  1023. value = pSheet->GetInstanceProperties().value; \
  1024. TRACEEOLID(value);
  1025. #define END_META_INST_READ(err)\
  1026. \
  1027. } \
  1028. while(FALSE); \
  1029. }
  1030. #define BEGIN_META_DIR_READ(sheet)\
  1031. { \
  1032. sheet * pSheet = (sheet *)GetSheet(); \
  1033. do \
  1034. { \
  1035. if (FAILED(pSheet->QueryDirectoryResult())) \
  1036. { \
  1037. break; \
  1038. }
  1039. #define FETCH_DIR_DATA_FROM_SHEET(value)\
  1040. value = pSheet->GetDirectoryProperties().value; \
  1041. TRACEEOLID(value);
  1042. #define END_META_DIR_READ(err)\
  1043. \
  1044. } \
  1045. while(FALSE); \
  1046. }
  1047. #define BEGIN_META_INST_WRITE(sheet)\
  1048. { \
  1049. sheet * pSheet = (sheet *)GetSheet(); \
  1050. \
  1051. do \
  1052. { \
  1053. #define STORE_INST_DATA_ON_SHEET(value)\
  1054. pSheet->GetInstanceProperties().value = value;
  1055. #define STORE_INST_DATA_ON_SHEET_REMEMBER(value, dirty)\
  1056. pSheet->GetInstanceProperties().value = value; \
  1057. dirty = MP_D(((sheet *)GetSheet())->GetInstanceProperties().value);
  1058. #define FLAG_INST_DATA_FOR_DELETION(id)\
  1059. pSheet->GetInstanceProperties().FlagPropertyForDeletion(id);
  1060. #define END_META_INST_WRITE(err)\
  1061. \
  1062. } \
  1063. while(FALSE); \
  1064. \
  1065. err = pSheet->GetInstanceProperties().WriteDirtyProps(); \
  1066. }
  1067. #define BEGIN_META_DIR_WRITE(sheet)\
  1068. { \
  1069. sheet * pSheet = (sheet *)GetSheet(); \
  1070. \
  1071. do \
  1072. { \
  1073. #define STORE_DIR_DATA_ON_SHEET(value)\
  1074. pSheet->GetDirectoryProperties().value = value;
  1075. #define STORE_DIR_DATA_ON_SHEET_REMEMBER(value, dirty)\
  1076. pSheet->GetDirectoryProperties().value = value; \
  1077. dirty = MP_D(pSheet->GetDirectoryProperties().value);
  1078. #define INIT_DIR_DATA_MASK(value, mask)\
  1079. MP_V(pSheet->GetDirectoryProperties().value).SetMask(mask);
  1080. #define FLAG_DIR_DATA_FOR_DELETION(id)\
  1081. pSheet->GetDirectoryProperties().FlagPropertyForDeletion(id);
  1082. #define END_META_DIR_WRITE(err)\
  1083. \
  1084. } \
  1085. while(FALSE); \
  1086. \
  1087. err = pSheet->GetDirectoryProperties().WriteDirtyProps(); \
  1088. }
  1089. //
  1090. // Inline Expansion
  1091. //
  1092. // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  1093. inline BOOL CMaskedDWORD::operator ==(DWORD dwValue) const
  1094. {
  1095. return (m_dwValue & m_dwMask) == (dwValue & m_dwMask);
  1096. }
  1097. inline CMaskedDWORD & CMaskedDWORD::operator =(DWORD dwValue)
  1098. {
  1099. m_dwValue = ((m_dwValue &= ~m_dwMask) |= (dwValue & m_dwMask));
  1100. return *this;
  1101. }
  1102. inline /*virtual */ HRESULT CMetaProperties::WriteDirtyProps()
  1103. {
  1104. ASSERT_MSG("Not implemented");
  1105. return E_NOTIMPL;
  1106. }
  1107. inline void CMetaProperties::FlagPropertyForDeletion(DWORD dwID)
  1108. {
  1109. m_dwaDeletedProps.AddTail(dwID);
  1110. }
  1111. inline LPCTSTR CInstanceProps::GetDisplayText(
  1112. OUT CString & strName
  1113. //IN LPCTSTR szServiceName
  1114. )
  1115. {
  1116. return CInstanceProps::GetDisplayText(
  1117. strName,
  1118. m_strComment,
  1119. m_strDomainName,
  1120. //szServiceName,
  1121. m_iaIpAddress,
  1122. m_nTCPPort,
  1123. QueryInstance()
  1124. );
  1125. }
  1126. inline LPCTSTR CInstanceProps::GetHomePath(CString & str)
  1127. {
  1128. str = m_strMetaRoot + SZ_MBN_SEP_STR + g_cszRoot;
  1129. return str;
  1130. }
  1131. inline void CChildNodeProps::RemovePathIfInherited()
  1132. {
  1133. if (IsPathInherited())
  1134. {
  1135. MP_V(m_strPath).Empty();
  1136. }
  1137. }
  1138. /*
  1139. inline void CChildNodeProps::FillInstanceInfo(ISMINSTANCEINFO * pii)
  1140. {
  1141. _tcsncpy(pii->szPath, GetPath(), STRSIZE(pii->szPath));
  1142. _tcsncpy(pii->szRedirPath, GetRedirectedPath(), STRSIZE(pii->szRedirPath));
  1143. pii->fChildOnlyRedir = m_fChild;
  1144. }
  1145. inline void CChildNodeProps::FillChildInfo(ISMCHILDINFO * pii)
  1146. {
  1147. //
  1148. // Set the output structure
  1149. //
  1150. pii->fInheritedPath = IsPathInherited();
  1151. pii->fEnabledApplication = IsEnabledApplication();
  1152. pii->dwError = QueryWin32Error();
  1153. _tcsncpy(
  1154. pii->szAlias,
  1155. GetAlias(),
  1156. STRSIZE(pii->szAlias)
  1157. );
  1158. _tcsncpy(
  1159. pii->szPath,
  1160. GetPath(),
  1161. STRSIZE(pii->szPath)
  1162. );
  1163. _tcsncpy(
  1164. pii->szRedirPath,
  1165. IsRedirected() ? GetRedirectedPath() : _T(""),
  1166. STRSIZE(pii->szRedirPath)
  1167. );
  1168. pii->fChildOnlyRedir = m_fChild;
  1169. }
  1170. */
  1171. #endif // _INETPROP_H_