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.

126 lines
3.9 KiB

  1. #ifndef _POLICYCF_H
  2. #define _POLICYCF_H
  3. #define CFSTR_WIFIPOLICYOBJECT L"WIFI_POLICYOBJECT"
  4. #define POByteOffset(base, offset) (((LPBYTE)base)+offset)
  5. typedef struct
  6. {
  7. DWORD m_dwInterfaceFlags;
  8. long m_lMMCUpdateHandle;
  9. DWORD m_dwOffsetObjClass;
  10. DWORD m_dwOffsetObjPath;
  11. DWORD m_dwOffsetRemoteMachineName;
  12. } POLICYOBJECTSTRUCT;
  13. class POLICYOBJECT
  14. {
  15. public:
  16. // Policy Object flags
  17. #define POFLAG_INVALID 0x00000000
  18. #define POFLAG_NEW 0x00000002
  19. #define POFLAG_EDIT 0x00000004
  20. #define POFLAG_APPLY 0x00000008
  21. #define POFLAG_CANCEL 0x00000010
  22. #define POFLAG_LOCAL 0x00000020
  23. #define POFLAG_GLOBAL 0x00000040
  24. #define POFLAG_REMOTE 0x00000080
  25. POLICYOBJECT ()
  26. {
  27. dwInterfaceFlags (POFLAG_INVALID);
  28. lMMCUpdateHandle (0);
  29. };
  30. ~POLICYOBJECT () {};
  31. // memory allocation helpers
  32. int DataGlobalAllocLen ()
  33. {
  34. return (sizeof (POLICYOBJECTSTRUCT) +
  35. m_sObjClass.GetLength()*sizeof(wchar_t)+sizeof(wchar_t) +
  36. m_sObjPath.GetLength()*sizeof(wchar_t)+sizeof(wchar_t) +
  37. m_sRemoteMachineName.GetLength()*sizeof(wchar_t)+sizeof(wchar_t));
  38. }
  39. HRESULT FromObjMedium (STGMEDIUM* pObjMedium)
  40. {
  41. HRESULT hr = E_UNEXPECTED;
  42. POLICYOBJECTSTRUCT* pPolicyStruct = (POLICYOBJECTSTRUCT*) pObjMedium->hGlobal;
  43. if (pPolicyStruct)
  44. {
  45. m_dwInterfaceFlags = pPolicyStruct->m_dwInterfaceFlags;
  46. m_lMMCUpdateHandle = pPolicyStruct->m_lMMCUpdateHandle;
  47. m_sObjPath = (LPWSTR)POByteOffset(pPolicyStruct, pPolicyStruct->m_dwOffsetObjPath);
  48. m_sObjClass = (LPWSTR)POByteOffset(pPolicyStruct, pPolicyStruct->m_dwOffsetObjClass);
  49. m_sRemoteMachineName = (LPWSTR)POByteOffset(pPolicyStruct, pPolicyStruct->m_dwOffsetRemoteMachineName);
  50. hr = S_OK;
  51. }
  52. return hr;
  53. }
  54. HRESULT ToPolicyStruct (POLICYOBJECTSTRUCT* pPolicyStruct)
  55. {
  56. HRESULT hr = E_UNEXPECTED;
  57. if (pPolicyStruct)
  58. {
  59. pPolicyStruct->m_dwInterfaceFlags = m_dwInterfaceFlags;
  60. pPolicyStruct->m_lMMCUpdateHandle = m_lMMCUpdateHandle;
  61. // store ObjPath
  62. int istrlenObjPath = m_sObjPath.GetLength()*sizeof(wchar_t)+sizeof(wchar_t);
  63. int iStructLen = sizeof (POLICYOBJECTSTRUCT);
  64. LONG_PTR addr = ((LONG_PTR)(pPolicyStruct)) + iStructLen;
  65. memcpy((void*)addr,m_sObjPath,istrlenObjPath);
  66. pPolicyStruct->m_dwOffsetObjPath=iStructLen;
  67. // store ObjClass
  68. // using the current istrlen (length of ObjPath) determine new address and offset for the class
  69. addr = addr + istrlenObjPath;
  70. pPolicyStruct->m_dwOffsetObjClass=iStructLen+istrlenObjPath;
  71. // get new strlen and copy the class in
  72. int istrlenObjClass = m_sObjClass.GetLength()*sizeof(wchar_t)+sizeof(wchar_t);
  73. memcpy((void*)addr,m_sObjClass,istrlenObjClass);
  74. // store RemoteMachineName
  75. // using istrlenObjClass (length of ObjClass) determine new address and offset for the class
  76. addr = addr + istrlenObjClass;
  77. pPolicyStruct->m_dwOffsetRemoteMachineName=iStructLen+istrlenObjPath+istrlenObjClass;
  78. // get new strlen and copy the class in
  79. int istrlenRemoteMachineName = m_sRemoteMachineName.GetLength()*sizeof(wchar_t)+sizeof(wchar_t);
  80. memcpy((void*)addr,m_sRemoteMachineName,istrlenRemoteMachineName);
  81. hr = S_OK;
  82. }
  83. return hr;
  84. }
  85. // member access methods
  86. DWORD dwInterfaceFlags() {return m_dwInterfaceFlags;}
  87. void dwInterfaceFlags (DWORD dw) {m_dwInterfaceFlags = dw;}
  88. long lMMCUpdateHandle() {return m_lMMCUpdateHandle;}
  89. void lMMCUpdateHandle (long l) {m_lMMCUpdateHandle = l;}
  90. CString ObjClass() {return m_sObjClass;}
  91. void ObjClass (CString s) {m_sObjClass = s;}
  92. CString ObjPath() {return m_sObjPath;}
  93. void ObjPath (CString s) {m_sObjPath = s;}
  94. CString RemoteMachineName() {return m_sRemoteMachineName;}
  95. void RemoteMachineName (CString s) {m_sRemoteMachineName = s;}
  96. private:
  97. DWORD m_dwInterfaceFlags;
  98. long m_lMMCUpdateHandle;
  99. CString m_sObjClass;
  100. CString m_sObjPath;
  101. CString m_sRemoteMachineName;
  102. };
  103. #endif // _POLICYCF_H