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.

201 lines
6.7 KiB

  1. /*++
  2. Copyright (C) 1997-2000 Microsoft Corporation
  3. Module Name:
  4. Import.h
  5. Abstract:
  6. Upgrade code
  7. History:
  8. --*/
  9. #ifndef __wmi_import_h__
  10. #define __wmi_import_h__
  11. /*================================================================================
  12. *
  13. * EXPORT FILE FORMAT
  14. * ==================
  15. *
  16. * File Header Block:
  17. * wchar_t wszFileHeader = "repexp1"
  18. *
  19. * Namespace Block:
  20. * DWORD dwObjectType = 0x00000001
  21. * DWORD dwNamespaceNameSize
  22. * wchar_t wszNamespaceName[dwNamespaceNameSize] = Full namespace name
  23. * (\root\default\fred)
  24. *
  25. * Class Block:
  26. * DWORD dwObjectType = 0x00000002
  27. * DWORD dwClassNameSize
  28. * wchar_t wszClassName[dwClassNameSize] = Class name (my_class_name)
  29. * DWORD dwClassObjectSize
  30. * DWORD adwClassObject[dwClassObjectSize]
  31. *
  32. * Instance Block - key of type int:
  33. * DWORD dwObjectType = 0x00000003
  34. * DWORD dwInstanceKey
  35. * DWORD dwInstanceObjectSize
  36. * DWORD adwInstanceObject[dwInstanceObjectSize]
  37. *
  38. * Instance Block - key of type string
  39. * DWORD dwObjectType = 0x00000004
  40. * DWORD dwInstanceKeySize
  41. * DWORD dwInstanceKey[dwInstanceKeySize] = Instance key (MyKeyValue)
  42. * DWORD dwInstanceObjectSize
  43. * DWORD adwInstanceObject[dwInstanceObjectSize]
  44. *
  45. * End of class block
  46. * DWORD dwObjectType = 0x00000005
  47. * DWORD dwEndOfBlockSize = 0x00000010
  48. * DWORD adwEndOfBlock[dwEndOfBlockSize] = 0xFFFFFFFF,
  49. * 0xFFFFFFFF,
  50. * 0xFFFFFFFF,
  51. * 0xFFFFFFFF
  52. *
  53. * End of namespace block
  54. * DWORD dwObjectType = 0x00000006
  55. * DWORD dwEndOfBlockSize = 0x00000010
  56. * DWORD adwEndOfBlock[dwEndOfBlockSize] = 0xFFFFFFFF,
  57. * 0xFFFFFFFF,
  58. * 0xFFFFFFFF,
  59. * 0xFFFFFFFF
  60. *
  61. * End of file block
  62. * DWORD dwObjectType = 0xFFFFFFFF
  63. * DWORD dwEndOfBlockSize = 0x00000010
  64. * DWORD adwEndOfBlock[dwEndOfBlockSize] = 0xFFFFFFFF,
  65. * 0xFFFFFFFF,
  66. * 0xFFFFFFFF,
  67. * 0xFFFFFFFF
  68. *
  69. * Ordering:
  70. * File Header Block
  71. * (one or more)
  72. * Namespace Block
  73. * (zero or more)
  74. * {
  75. * Namespace Block
  76. * etc...
  77. * End namespace block
  78. * (or)
  79. * Class Block
  80. * (zero or more)
  81. * {
  82. * Instance Block
  83. * (or)
  84. * Class Block
  85. * etc...
  86. * End class block
  87. * }
  88. * End class block
  89. * }
  90. * End namespace block
  91. * End of file block
  92. *
  93. *================================================================================
  94. */
  95. #include <wbemint.h>
  96. #include <strutils.h>
  97. #include "flexarry.h"
  98. #include "winntsec.h"
  99. #ifndef FULL_RIGHTS
  100. #define FULL_RIGHTS WBEM_METHOD_EXECUTE | WBEM_FULL_WRITE_REP | WBEM_PARTIAL_WRITE_REP | \
  101. WBEM_WRITE_PROVIDER | WRITE_DAC | READ_CONTROL | WBEM_ENABLE | WBEM_REMOTE_ACCESS
  102. #endif
  103. #define BLOB9X_FILENAME L"\\WBEM9xUpgd.dat"
  104. #define BLOB9X_SIGNATURE "9xUpgrade" //NOTE! MAXIMUM OF 10 CHARACTERS (INCLUDING TERMINATOR!)
  105. #define BLOB9X_TYPE_SECURITY_BLOB 1
  106. #define BLOB9X_TYPE_SECURITY_INSTANCE 2
  107. #define BLOB9X_TYPE_END_OF_FILE 3
  108. typedef struct _BLOB9X_HEADER
  109. {
  110. char szSignature[10];
  111. } BLOB9X_HEADER;
  112. typedef struct _BLOB9X_SPACER
  113. {
  114. DWORD dwSpacerType;
  115. DWORD dwNamespaceNameSize;
  116. DWORD dwParentClassNameSize;
  117. DWORD dwBlobSize;
  118. } BLOB9X_SPACER;
  119. class CRepImporter
  120. {
  121. private:
  122. HANDLE m_hFile;
  123. HANDLE m_h9xBlobFile;
  124. bool m_bSecurityMode;
  125. bool CheckOldSecurityClass(const wchar_t* wszClass);
  126. void DecodeTrailer();
  127. void DecodeInstanceInt(IWbemServices* pNamespace, const wchar_t *wszFullPath, const wchar_t *pszParentClass, _IWmiObject* pOldParentClass, _IWmiObject *pNewParentClass);
  128. void DecodeInstanceString(IWbemServices* pNamespace, const wchar_t *wszFullPath, const wchar_t *pszParentClass, _IWmiObject* pOldParentClass, _IWmiObject *pNewParentClass);
  129. void DecodeClass(IWbemServices* pNamespace, const wchar_t *wszFullPath, const wchar_t *wszParentClass, _IWmiObject *pOldParentClass, _IWmiObject *pNewParentClass);
  130. void DecodeNamespace(IWbemServices* pNamespace, const wchar_t *wszParentNamespace);
  131. void DecodeNamespaceSecurity(IWbemServices* pNamespace, IWbemServices* pParentNamespace, const char* pNsSecurity, DWORD dwSize, const wchar_t* wszFullPath);
  132. void Decode();
  133. // helpers for DecodeNamespaceSecurity
  134. bool TransformBlobToSD(IWbemServices* pParentNamespace, const char* pNsSecurity, DWORD dwStoredAsNT, CNtSecurityDescriptor& mmfNsSD);
  135. bool SetNamespaceSecurity(IWbemServices* pNamespace, CNtSecurityDescriptor& mmfNsSD);
  136. bool AddDefaultRootAces(CNtAcl * pacl);
  137. bool GetParentsInheritableAces(IWbemServices* pParentNamespace, CNtSecurityDescriptor &sd);
  138. bool StripOutInheritedAces(CNtSecurityDescriptor &sd);
  139. bool GetSDFromNamespace(IWbemServices* pNamespace, CNtSecurityDescriptor& sd);
  140. bool CopyInheritAces(CNtSecurityDescriptor& sd, CNtSecurityDescriptor& sdParent);
  141. BOOL SetOwnerAndGroup(CNtSecurityDescriptor &sd);
  142. void ForceInherit();
  143. bool InheritSecurity(IWbemLocator* pLocator, IWbemServices* pRootNamespace, const wchar_t* wszNamespace);
  144. void ConnectNamespace(IWbemLocator* pLocator, const wchar_t* wszNamespaceName, IWbemServices** ppNamespace);
  145. bool CheckNetworkLocalService ( CNtSecurityDescriptor& sd ) ;
  146. // helpers for Win9x security processing
  147. bool AppendWin9xBlobFile(const wchar_t* wszFullPath, DWORD dwBlobSize, const char* pNsSecurity);
  148. bool AppendWin9xBlobFile(const wchar_t* wszFullPath, const wchar_t* wszParentClass, _IWmiObject* pInstance);
  149. bool CreateWin9xBlobFile();
  150. void DeleteWin9xBlobFile();
  151. bool GetRepositoryDirectory(wchar_t wszRepositoryDirectory[MAX_PATH+1]);
  152. bool CloseWin9xBlobFile();
  153. public:
  154. CRepImporter() : m_hFile(INVALID_HANDLE_VALUE), m_h9xBlobFile(INVALID_HANDLE_VALUE), m_bSecurityMode(false){};
  155. int ImportRepository(const TCHAR *pszFromFile);
  156. enum { FAILURE_READ = 1,
  157. FAILURE_INVALID_FILE = 2,
  158. FAILURE_INVALID_TYPE = 3,
  159. FAILURE_INVALID_TRAILER = 4,
  160. FAILURE_CANNOT_FIND_NAMESPACE = 5,
  161. FAILURE_CANNOT_GET_PARENT_CLASS = 6,
  162. FAILURE_CANNOT_CREATE_INSTANCE = 7,
  163. FAILURE_CANNOT_ADD_NAMESPACE = 8,
  164. FAILURE_CANNOT_ADD_NAMESPACE_SECURITY= 9,
  165. FAILURE_OUT_OF_MEMORY = 10,
  166. FAILURE_CANNOT_CREATE_IWBEMLOCATOR = 11,
  167. FAILURE_CANNOT_CONNECT_SERVER = 12,
  168. FAILURE_CANNOT_MERGE_INSTANCE = 13,
  169. FAILURE_CANNOT_UPGRADE_INSTANCE = 14,
  170. FAILURE_CANNOT_MERGE_CLASS = 15,
  171. FAILURE_CANNOT_UPGRADE_CLASS = 16,
  172. FAILURE_CANNOT_CREATE_CLASS = 17,
  173. FAILURE_CANNOT_CREATE_OBJECTFACTORY = 18,
  174. FAILURE_CANNOT_CREATE_IWMIOBJECT = 19
  175. };
  176. };
  177. #endif