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.

189 lines
5.5 KiB

  1. #pragma once
  2. #include "wrappers.h"
  3. struct _CallbackInfo
  4. {
  5. typedef void (*PFN_CALLBACK)( void*, LPCWSTR, bool );
  6. _CallbackInfo( PFN_CALLBACK pCB = NULL, void* pContext = NULL )
  7. {
  8. pCallback = pCB;
  9. pCtx = pContext;
  10. }
  11. PFN_CALLBACK pCallback;
  12. void* pCtx;
  13. };
  14. // Class for writing files to the package
  15. // Note that the class does not own any of the handles it contains. It just caches them
  16. /////////////////////////////////////////////////////////////////////////////////////////
  17. class COutPackage
  18. {
  19. // Data types
  20. public:
  21. enum AddFileOptions
  22. {
  23. afNone = 0x0000,
  24. afNoDACL = 0x0001,
  25. afAllowNoInhAce = 0x0002, // Allows for inherited ACEs to be not exported.
  26. };
  27. private:
  28. enum
  29. {
  30. DefaultBufferSize = 4 * 1024,
  31. };
  32. enum _SidType
  33. {
  34. sidInvalid,
  35. sidIISUser,
  36. sidWellKnown,
  37. sidExternal
  38. };
  39. // Used for exporting file object's security settings
  40. typedef std::list<_sid_ptr> TSIDList;
  41. // Ctor / Dtor
  42. public:
  43. COutPackage ( HANDLE hFile, bool bCompress, HCRYPTKEY hCryptKey );
  44. // Class interface
  45. public:
  46. void AddFile ( LPCWSTR wszName,
  47. const IXMLDOMDocumentPtr& spXMLDoc,
  48. const IXMLDOMElementPtr& spEl,
  49. DWORD dwOptions )const;
  50. void AddPath ( LPCWSTR wszPath,
  51. const IXMLDOMDocumentPtr& spXMLDoc,
  52. const IXMLDOMElementPtr& spEl,
  53. DWORD dwOptions )const;
  54. void WriteSIDsToXML ( DWORD dwSiteID,
  55. const IXMLDOMDocumentPtr& spXMLDoc,
  56. const IXMLDOMElementPtr& spEl )const;
  57. void ResetSIDList ( void )const{ m_SIDList.clear();}
  58. void SetCallback ( const _CallbackInfo& Info )const
  59. {
  60. m_CallbackInfo = Info;
  61. }
  62. // Implementation
  63. private:
  64. DWORDLONG GetCurrentPos ( void )const;
  65. void ExportFileDACL ( LPCWSTR wszObject,
  66. const IXMLDOMDocumentPtr& spDoc,
  67. const IXMLDOMElementPtr& spRoot,
  68. bool bAllowSkipInherited )const;
  69. void ExportAce ( LPVOID pACE,
  70. const IXMLDOMDocumentPtr& spDoc,
  71. const IXMLDOMElementPtr& spRoot,
  72. bool bAllowSkipInherited )const;
  73. DWORD IDFromSID ( PSID pSID )const;
  74. bool GetSIDDetails ( PSID pSID,
  75. LPCWSTR wszIISUser,
  76. LPCWSTR wszMachine,
  77. std::wstring& rstrAccount,
  78. std::wstring& rstrDomain,
  79. SID_NAME_USE& rSidUsage,
  80. _SidType& rSidType )const;
  81. void WriteSIDToXML ( const IXMLDOMElementPtr& spSid,
  82. DWORD dwID,
  83. LPCWSTR wszAccount,
  84. LPCWSTR wszDomain,
  85. SID_NAME_USE SidUsage,
  86. _SidType SidType )const;
  87. void RemoveSidFromXML( const IXMLDOMDocumentPtr& spDoc, DWORD nSidID )const;
  88. void AddPathOnly ( LPCWSTR wszPath,
  89. LPCWSTR wszName,
  90. const IXMLDOMDocumentPtr& spXMLDoc,
  91. const IXMLDOMElementPtr& spEl,
  92. DWORD dwOptions )const;
  93. // Data members
  94. private:
  95. mutable TSIDList m_SIDList; // Contains all SIDs for files, added to the package
  96. HANDLE m_hFile; // The file handle
  97. bool m_bCompress; // If true - files are compressed
  98. HCRYPTKEY m_hCryptKey; // If not null - used to encrypt files
  99. TByteAutoPtr m_spBuffer; // Buffer used for the file operations
  100. mutable _CallbackInfo m_CallbackInfo; // Calbback for add file
  101. };
  102. // Class for restoring files/dirs from the package
  103. /////////////////////////////////////////////////////////////////////////////////////////
  104. class CInPackage
  105. {
  106. // Data types
  107. public:
  108. enum ExtractDirOptions
  109. {
  110. edNone = 0x0000,
  111. edNoDACL = 0x0001 // Security settings will not be extracted
  112. };
  113. private:
  114. typedef std::map<DWORD, _sid_ptr> TSIDMap; // These are the SIDs for file/dir permissions
  115. enum
  116. {
  117. DefaultBufferSize = 4 * 1024,
  118. };
  119. // Class interface
  120. public:
  121. CInPackage ( const IXMLDOMNodePtr& spSite,
  122. HANDLE hFile,
  123. bool bCompressed,
  124. HCRYPTKEY hDecryptKey );
  125. void ExtractVDir ( const IXMLDOMNodePtr& spVDir, DWORD dwOptions );
  126. void ExtractFile ( const IXMLDOMNodePtr& spFile, LPCWSTR wszDir, DWORD dwOptions );
  127. void SetCallback ( const _CallbackInfo& Info )const
  128. {
  129. m_CallbackInfo = Info;
  130. }
  131. // Implementation
  132. private:
  133. void LoadSIDs ( const IXMLDOMNodePtr& spSIDs );
  134. bool LookupSID ( const IXMLDOMNodePtr& spSID,
  135. LPCWSTR wszLocalMachine,
  136. LPCWSTR wszSourceMachine,
  137. DWORD& rdwID,
  138. TByteAutoPtr& rspData );
  139. void ExtractDir ( const IXMLDOMNodePtr& spDir, LPCWSTR wszRoot, DWORD dwOptions );
  140. void ApplyFileObjSecurity( const IXMLDOMNodePtr& spObj, LPCWSTR wszName );
  141. // Data
  142. private:
  143. TSIDMap m_SIDs; // SID used for file.dir access permissions
  144. HANDLE m_hFile; // The input file ( the package )
  145. bool m_bCompressed; // Is the package data compressed
  146. HCRYPTKEY m_hDecryptKey; // Used to decrypt the data. If NULL - data is not encrypted
  147. TByteAutoPtr m_spBuffer; // General memory buffer
  148. mutable _CallbackInfo m_CallbackInfo;
  149. };