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.

384 lines
18 KiB

  1. // -----------------------------------------------------------------------------
  2. // I P R O P O B J . H - Steven J. Bailey - 8/17/96
  3. // -----------------------------------------------------------------------------
  4. #ifndef __IPROPOBJ_H
  5. #define __IPROPOBJ_H
  6. // ------------------------------------------------------------------------------------------
  7. // Depends On
  8. // ------------------------------------------------------------------------------------------
  9. #include "imnact.h"
  10. // ------------------------------------------------------------------------------------------
  11. // Forward Decls
  12. // ------------------------------------------------------------------------------------------
  13. class CPropCrypt;
  14. // ------------------------------------------------------------------------------------------
  15. // Macros for defining imn property tags
  16. // ------------------------------------------------------------------------------------------
  17. #define CCHMAX_PROPERTY_NAME 255
  18. // ------------------------------------------------------------------------------------------
  19. // Password structure
  20. // ------------------------------------------------------------------------------------------
  21. struct tagPROPPASS {
  22. LPBYTE pbRegData;
  23. BLOB blobPassword;
  24. };
  25. typedef struct tagPROPPASS PROPPASS;
  26. typedef PROPPASS *LPPROPPASS;
  27. // ------------------------------------------------------------------------------------------
  28. // Union of property value types
  29. // ------------------------------------------------------------------------------------------
  30. typedef union tagXVARIANT {
  31. DWORD Dword; // TYPE_DWORD
  32. LONG Long; // TYPE_LONG
  33. WORD Word; // TYPE_WORD
  34. SHORT Short; // TYPE_SHORT
  35. BYTE Byte; // TYPE_BYTE
  36. CHAR Char; // TYPE_CHAR
  37. FILETIME Filetime; // TYPE_FLETIME
  38. DWORD Flags; // TYPE_FLAGS
  39. LPSTR Lpstring; // TYPE_STRING
  40. LPWSTR Lpwstring; // TYPE_WSTRING;
  41. LPBYTE Lpbyte; // TYPE_BINARY
  42. LPSTREAM Lpstream; // TYPE_STREAM
  43. DWORD Bool; // TYPE_BOOL
  44. LPPROPPASS pPass; // TYPE_PASS
  45. ULARGE_INTEGER uhVal; // TYPE_ULARGEINTEGER
  46. } XVARIANT, *LPXVARIANT;
  47. typedef const XVARIANT *LPCXVARIANT;
  48. // ------------------------------------------------------------------------------------------
  49. // Min Max Data Type
  50. // ------------------------------------------------------------------------------------------
  51. typedef struct tagMINMAX {
  52. DWORD dwMin;
  53. DWORD dwMax;
  54. } MINMAX, *LPMINMAX;
  55. // ------------------------------------------------------------------------------------------
  56. // Value Flags
  57. // ------------------------------------------------------------------------------------------
  58. #define PV_WriteDirty FLAG01 // Has it been modified by a HrSetProperty
  59. #define PV_ValueSet FLAG02 // Is the value set or is it un-initialized
  60. #define PV_UsingDefault FLAG03 // Are we using the default value for HrGetProperty
  61. #define PV_CustomProperty FLAG04 // Is this a custom property (i.e. not in known propset range)
  62. #define PV_SetOnLoad FLAG05 // Value was set during a EnterLoadContainer
  63. // ------------------------------------------------------------------------------------------
  64. // PROPVALUE
  65. // ------------------------------------------------------------------------------------------
  66. typedef struct tagPROPVALUE {
  67. DWORD dwPropTag; // PropTag (id and type) of property
  68. DWORD dwPropFlags; // Property Flags, same as PROPINFO::dwFlags
  69. DWORD dwValueFlags; // Value Flags
  70. DWORD cbAllocated; // Number of bytes allocated for dynamic properties
  71. DWORD cbValue; // Length of property
  72. LPBYTE pbValue; // Pointer into Value union
  73. XVARIANT Variant; // Union of typed property values
  74. MINMAX rMinMax; // Valid range or size of property
  75. } PROPVALUE, *LPPROPVALUE;
  76. // ------------------------------------------------------------------------------------------
  77. // Property Flags
  78. // ------------------------------------------------------------------------------------------
  79. #define NOFLAGS 0
  80. #define PF_REQUIRED 1
  81. #define PF_NOPERSIST 2
  82. #define PF_READONLY 4
  83. #define PF_VARLENGTH 8
  84. #define PF_ENCRYPTED 16
  85. #define PF_MINMAX 32
  86. #define PF_DEFAULT 64
  87. // ------------------------------------------------------------------------------------------
  88. // Default for propinfo
  89. // ------------------------------------------------------------------------------------------
  90. typedef struct tagPROPDEFAULT {
  91. XVARIANT Variant; // Default Variant Type
  92. DWORD cbValue; // Size of default value
  93. } PROPDEFAULT, *LPPROPDEFAULT;
  94. // ------------------------------------------------------------------------------------------
  95. // Property Info - Used to create Property Set Arrays
  96. // ------------------------------------------------------------------------------------------
  97. typedef struct tagPROPINFO {
  98. DWORD dwPropTag; // Property tag
  99. LPTSTR pszName; // Property name
  100. DWORD dwFlags; // Propety flags (above)
  101. PROPDEFAULT Default; // Default Value for property
  102. MINMAX rMinMax; // Valid range or size of property
  103. } PROPINFO, *LPPROPINFO;
  104. typedef const PROPINFO *LPCPROPINFO;
  105. // -----------------------------------------------------------------------------
  106. // PSETINFO
  107. // -----------------------------------------------------------------------------
  108. typedef struct tagPSETINFO {
  109. LPPROPINFO prgPropInfo;
  110. ULONG cProperties;
  111. ULONG ulPropIdMin;
  112. ULONG ulPropIdMax;
  113. PROPINFO **rgpInfo;
  114. ULONG cpInfo;
  115. } PSETINFO, *LPPSETINFO;
  116. // -----------------------------------------------------------------------------
  117. // CPropertySet
  118. // -----------------------------------------------------------------------------
  119. class CPropertySet
  120. {
  121. private:
  122. ULONG m_cRef; // Reference Counting
  123. ULONG m_cProperties; // Number of properties in propset
  124. ULONG m_ulPropIdMin; // Lowest prop id
  125. ULONG m_ulPropIdMax; // Largest prop id
  126. BOOL m_fInit; // Has the object been initialized successfully
  127. LPPROPINFO m_prgPropInfo; // Property set inforation
  128. LPPROPVALUE m_prgPropValue; // Sorted propdata template array
  129. CRITICAL_SECTION m_cs; // Critical Section
  130. PROPINFO **m_rgpInfo;
  131. ULONG m_cpInfo;
  132. private:
  133. // -------------------------------------------------------------------------
  134. // Prepare this object to be re-used - may be public someday
  135. // -------------------------------------------------------------------------
  136. VOID ResetPropertySet(VOID);
  137. public:
  138. // -------------------------------------------------------------------------
  139. // Standard Object Stuff
  140. // -------------------------------------------------------------------------
  141. CPropertySet();
  142. ~CPropertySet();
  143. ULONG AddRef(VOID);
  144. ULONG Release(VOID);
  145. // -------------------------------------------------------------------------
  146. // Use to validate property tags
  147. // -------------------------------------------------------------------------
  148. BOOL FIsValidPropTag(DWORD dwPropTag);
  149. // -------------------------------------------------------------------------
  150. // Computes index into propinfo or propdata arrays
  151. // -------------------------------------------------------------------------
  152. HRESULT HrIndexFromPropTag(DWORD dwPropTag, ULONG *pi);
  153. // -------------------------------------------------------------------------
  154. // Initialize the property set with a know propset array
  155. // -------------------------------------------------------------------------
  156. HRESULT HrInit(LPCPROPINFO prgPropInfo, ULONG cProperties);
  157. // -------------------------------------------------------------------------
  158. // Lookup property info on a specific prop
  159. // -------------------------------------------------------------------------
  160. HRESULT HrGetPropInfo(DWORD dwPropTag, LPPROPINFO pPropInfo);
  161. HRESULT HrGetPropInfo(LPTSTR pszName, LPPROPINFO pPropInfo);
  162. // -------------------------------------------------------------------------
  163. // Generates propdata array used by CPropertyContainer. This object
  164. // maintains a sorted template propdata array. These can be somewhat
  165. // expensive to create, that why a CPropertySet can live outside of a
  166. // CPropertyContainer.
  167. // -------------------------------------------------------------------------
  168. HRESULT HrGetPropValueArray(LPPROPVALUE *pprgPropValue, ULONG *pcProperties);
  169. };
  170. // -----------------------------------------------------------------------------
  171. // Forward Decl
  172. // -----------------------------------------------------------------------------
  173. class CEnumProps;
  174. // -----------------------------------------------------------------------------
  175. // CPropertyContainer
  176. // -----------------------------------------------------------------------------
  177. class CPropertyContainer : public IPropertyContainer
  178. {
  179. protected:
  180. ULONG m_cRef; // Reference Count
  181. CPropertySet *m_pPropertySet; // Base property set
  182. LPPROPVALUE m_prgPropValue; // Array of property data items
  183. ULONG m_cDirtyProps; // Number of current dirty properties
  184. ULONG m_cProperties; // Number of properties known to container
  185. BOOL m_fLoading; // Properties are being set from persisted source
  186. CPropCrypt *m_pPropCrypt; // Property Encryption Object
  187. CRITICAL_SECTION m_cs; // Critical Section
  188. private:
  189. friend CEnumProps;
  190. // -------------------------------------------------------------------------
  191. // Used to group dynamic properties TYPE_STRING, TYPE_WSTRING and TYPE_BYTE
  192. // -------------------------------------------------------------------------
  193. HRESULT HrGrowDynamicProperty(DWORD cbNewSize, DWORD *pcbAllocated, LPBYTE *ppbData, DWORD dwUnitSize);
  194. // -------------------------------------------------------------------------
  195. // Property validation used during the base HrSetProp
  196. // -------------------------------------------------------------------------
  197. HRESULT HrValidateSetProp(PROPTYPE PropType, LPPROPVALUE pPropValue, LPBYTE pb, ULONG cb, LPMINMAX pMinMax);
  198. HRESULT GetEncryptedProp(PROPVALUE *ppv, LPBYTE pb, ULONG *pcb);
  199. public:
  200. // -------------------------------------------------------------------------
  201. // Standard Object Stuff
  202. // -------------------------------------------------------------------------
  203. CPropertyContainer(void);
  204. virtual ~CPropertyContainer(void);
  205. // -------------------------------------------------------------------------
  206. // IUnknown Methods
  207. // -------------------------------------------------------------------------
  208. STDMETHODIMP QueryInterface(REFIID, LPVOID *);
  209. STDMETHODIMP_(ULONG) AddRef(void);
  210. STDMETHODIMP_(ULONG) Release(void);
  211. // -------------------------------------------------------------------------
  212. // Verify State of the object
  213. // -------------------------------------------------------------------------
  214. HRESULT HrInit(CPropertySet *pPropertySet);
  215. // -------------------------------------------------------------------------
  216. // LoadingContainer - When reading the props from a persisted location,
  217. // you should call this function with TRUE, and then with FALSE when your
  218. // completed. This tells the container that the props you are setting are
  219. // not dirty, and that they are initial properties.
  220. // -------------------------------------------------------------------------
  221. BOOL FIsBeingLoaded(VOID);
  222. VOID EnterLoadContainer(VOID);
  223. VOID LeaveLoadContainer(VOID);
  224. VOID SetOriginalPropsToDirty(VOID);
  225. // -------------------------------------------------------------------------
  226. // Are there dirty properties in the container
  227. // -------------------------------------------------------------------------
  228. BOOL FIsDirty(VOID);
  229. HRESULT HrIsPropDirty(DWORD dwPropTag, BOOL *pfDirty);
  230. HRESULT HrSetPropDirty(DWORD dwPropTag, BOOL fDirty);
  231. HRESULT HrSetAllPropsDirty(BOOL fDirty);
  232. // -------------------------------------------------------------------------
  233. // Blow away all changes
  234. // -------------------------------------------------------------------------
  235. VOID ResetContainer(VOID);
  236. // -------------------------------------------------------------------------
  237. // Property Enumeration
  238. // -------------------------------------------------------------------------
  239. HRESULT HrEnumProps(CEnumProps **ppEnumProps);
  240. // -------------------------------------------------------------------------
  241. // HrGetProperty
  242. // -------------------------------------------------------------------------
  243. STDMETHODIMP GetProp(DWORD dwPropTag, LPBYTE pb, ULONG *pcb);
  244. STDMETHODIMP GetPropDw(DWORD dwPropTag, DWORD *pdw);
  245. STDMETHODIMP GetPropSz(DWORD dwPropTag, LPSTR psz, ULONG cchMax);
  246. // -------------------------------------------------------------------------
  247. // HrSetProperty
  248. // -------------------------------------------------------------------------
  249. STDMETHODIMP SetProp(DWORD dwPropTag, LPBYTE pb, ULONG cb);
  250. STDMETHODIMP SetPropDw(DWORD dwPropTag, DWORD dw);
  251. STDMETHODIMP SetPropSz(DWORD dwPropTag, LPSTR psz);
  252. // -------------------------------------------------------------------------
  253. // Access to CPropertSet Stuff
  254. // -------------------------------------------------------------------------
  255. HRESULT HrGetPropInfo(DWORD dwPropTag, LPPROPINFO pPropInfo);
  256. HRESULT HrGetPropInfo(LPTSTR pszName, LPPROPINFO pPropInfo);
  257. // -------------------------------------------------------------------------
  258. // Encryption
  259. // -------------------------------------------------------------------------
  260. HRESULT HrEncryptProp(LPBYTE pbClientData, DWORD cbClientData, LPBYTE *ppbPropData, DWORD *pcbPropData);
  261. HRESULT HrDecryptProp(BLOB *pIn, BLOB *pOut);
  262. HRESULT PersistEncryptedProp(DWORD dwPropTag, BOOL *pfPasswChanged);
  263. };
  264. // -----------------------------------------------------------------------------
  265. // CEnumProps - In the future, when I support custom properties, this will
  266. // be very useful and will know how to enumerate known and
  267. // custom properties as if they were a single array.
  268. // -----------------------------------------------------------------------------
  269. class CEnumProps
  270. {
  271. private:
  272. ULONG m_cRef; // Reference Count
  273. LONG m_iProperty; // Current property index into m_pPropValue, -1 == first item is next
  274. CPropertyContainer *m_pPropertyContainer; // Container that were enumerating, were friends
  275. public:
  276. // -------------------------------------------------------------------------
  277. // Standard Object Stuff
  278. // -------------------------------------------------------------------------
  279. CEnumProps(CPropertyContainer *pPropertyContainer);
  280. ~CEnumProps();
  281. ULONG AddRef(VOID);
  282. ULONG Release(VOID);
  283. // -------------------------------------------------------------------------
  284. // HrGetCount - Get the number of items that the enumerator will process
  285. // -------------------------------------------------------------------------
  286. HRESULT HrGetCount(ULONG *pcItems);
  287. // -------------------------------------------------------------------------
  288. // HrGetNext - Get the first or next enumerated propertiy
  289. // Returns hrEnumFinished when no more accounts to enumerate
  290. // -------------------------------------------------------------------------
  291. HRESULT HrGetNext(LPPROPVALUE pPropValue, LPPROPINFO pPropInfo);
  292. // -------------------------------------------------------------------------
  293. // HrGetCurrent - Get enumerated property that is the current one
  294. // Returns hrEnumFinished if no more accounts
  295. // -------------------------------------------------------------------------
  296. HRESULT HrGetCurrent(LPPROPVALUE pPropValue, LPPROPINFO pPropInfo);
  297. // -------------------------------------------------------------------------
  298. // Reset - This is like rewinding the enumerator
  299. // -------------------------------------------------------------------------
  300. VOID Reset(VOID);
  301. };
  302. // -----------------------------------------------------------------------------
  303. // IPersistPropertyContainer
  304. // -----------------------------------------------------------------------------
  305. class IPersistPropertyContainer : public CPropertyContainer
  306. {
  307. public:
  308. IPersistPropertyContainer(void);
  309. // HRESULT HrOpenTaggedPropStream(LPSTREAM pStream);
  310. // HRESULT HrSaveTaggedPropStream(LPSTREAM pStream);
  311. // HRESULT HrGetPersistedSize(DWORD *pcb);
  312. // virtual HRESULT HrOpenPropertyStream(DWORD dwPropTag, LPSTREAM *ppStream);
  313. virtual HRESULT HrSaveChanges(VOID) PURE;
  314. };
  315. // ------------------------------------------------------------------------------------------
  316. // Prototypes
  317. // ------------------------------------------------------------------------------------------
  318. HRESULT HrCreatePropertyContainer(CPropertySet *pPropertySet, CPropertyContainer **ppPropertyContainer);
  319. HRESULT PropUtil_HrRegTypeFromPropTag(DWORD dwPropTag, DWORD *pdwRegType);
  320. BOOL PropUtil_FRegCompatDataTypes(DWORD dwPropTag, DWORD dwRegType);
  321. HRESULT PropUtil_HrLoadContainerFromRegistry(HKEY hkeyReg, CPropertyContainer *pPropertyContainer);
  322. HRESULT PropUtil_HrPersistContainerToRegistry(HKEY hkeyReg, CPropertyContainer *pPropertyContainer, BOOL *fPasswChanged);
  323. #endif // __IPROPOBJ