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.

254 lines
6.8 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1997.
  5. //
  6. // File: validate.cpp
  7. //
  8. // Contents: validation routines
  9. //
  10. // Classes:
  11. //
  12. // Notes:
  13. //
  14. // History: 13-Aug-98 rogerg Created.
  15. //
  16. //--------------------------------------------------------------------------
  17. #include "lib.h"
  18. //+---------------------------------------------------------------------------
  19. //
  20. // function: IsValidSyncMgrItem
  21. //
  22. // Synopsis: validates SYNCMGRITEM
  23. //
  24. // Arguments:
  25. //
  26. // Returns: TRUE if valid.
  27. //
  28. // Modifies:
  29. //
  30. // History: 13-Aug-98 rogerg Created.
  31. //
  32. //+---------------------------------------------------------------------------
  33. BOOL IsValidSyncMgrItem(SYNCMGRITEM *poffItem)
  34. {
  35. BOOL fValid = TRUE;
  36. if (NULL == poffItem)
  37. {
  38. Assert(poffItem);
  39. return FALSE;
  40. }
  41. __try
  42. {
  43. if (poffItem->cbSize == sizeof(SYNCMGRITEM))
  44. {
  45. if ( (0 != (poffItem->dwFlags & ~(SYNCMGRITEM_ITEMFLAGMASK) ) )
  46. || (SYNCMGRITEMSTATE_CHECKED < poffItem->dwItemState) )
  47. {
  48. AssertSz(0,"Invalid SYNCMGRITEM returned from Enumerator");
  49. Assert(0 == (poffItem->dwFlags & ~(SYNCMGRITEM_ITEMFLAGMASK)));
  50. Assert(SYNCMGRITEMSTATE_CHECKED >= poffItem->dwItemState);
  51. fValid = FALSE;
  52. }
  53. else if (GUID_NULL == poffItem->ItemID)
  54. {
  55. AssertSz(0,"ItemID Cannot be GUID_NULL");
  56. fValid = FALSE;
  57. }
  58. }
  59. else
  60. {
  61. AssertSz(0,"Invalid SYNCMGRITEM returned from Enumerator");
  62. fValid = FALSE;
  63. }
  64. }
  65. __except(EXCEPTION_EXECUTE_HANDLER)
  66. {
  67. //bogus non-NULL pointer.
  68. AssertSz(0,"Bogus, non-NULL SYNCMGRITEM pointer returned from Enumerator");
  69. fValid = FALSE;
  70. }
  71. return fValid;
  72. }
  73. //+---------------------------------------------------------------------------
  74. //
  75. // function: IsValidSyncMgrHandlerInfo
  76. //
  77. // Synopsis: validates SYNCMGRITEM
  78. //
  79. // Arguments:
  80. //
  81. // Returns: TRUE if valid.
  82. //
  83. // Modifies:
  84. //
  85. // History: 13-Aug-98 rogerg Created.
  86. //
  87. //+---------------------------------------------------------------------------
  88. BOOL IsValidSyncMgrHandlerInfo(LPSYNCMGRHANDLERINFO pSyncMgrHandlerInfo)
  89. {
  90. // validate the arguments.
  91. __try
  92. {
  93. if ( (pSyncMgrHandlerInfo->cbSize != sizeof(SYNCMGRHANDLERINFO))
  94. || (0 != (pSyncMgrHandlerInfo->SyncMgrHandlerFlags & ~(SYNCMGRHANDLERFLAG_MASK))) )
  95. {
  96. AssertSz(0,"Invalid HandlerInfo Size returned from GetHandlerInfo");
  97. Assert(pSyncMgrHandlerInfo->cbSize == sizeof(SYNCMGRHANDLERINFO));
  98. Assert(0 == (pSyncMgrHandlerInfo->SyncMgrHandlerFlags & ~(SYNCMGRHANDLERFLAG_MASK)));
  99. return FALSE;
  100. }
  101. }
  102. __except(EXCEPTION_EXECUTE_HANDLER)
  103. {
  104. AssertSz(0,"Bogus, non-NULL LPSYNCMGRHANDLERINFO pointer.");
  105. return FALSE;
  106. }
  107. return TRUE;
  108. }
  109. //+---------------------------------------------------------------------------
  110. //
  111. // Function: IsValidSyncProgressItem, private
  112. //
  113. // Synopsis: Determines if the syncprogress item structure is valid
  114. //
  115. // Arguments: [lpProgItem] - Pointer to SyncProgress Item to validate.
  116. //
  117. // Returns: Returns true is the structure is valid.
  118. //
  119. // Modifies:
  120. //
  121. // History: 17-Nov-97 rogerg Created.
  122. //
  123. //----------------------------------------------------------------------------
  124. BOOL IsValidSyncProgressItem(LPSYNCMGRPROGRESSITEM lpProgItem)
  125. {
  126. if (NULL == lpProgItem)
  127. {
  128. Assert(lpProgItem);
  129. return FALSE;
  130. }
  131. __try
  132. {
  133. if (lpProgItem->cbSize != sizeof(SYNCMGRPROGRESSITEM))
  134. {
  135. AssertSz(0,"SYNCMGRPROGRESSITEM cbSize Incorrect");
  136. return FALSE;
  137. }
  138. if (lpProgItem->mask >= (SYNCMGRPROGRESSITEM_MAXVALUE << 1))
  139. {
  140. AssertSz(0,"Invalid ProgressItem Mask");
  141. return FALSE;
  142. }
  143. if (SYNCMGRPROGRESSITEM_STATUSTYPE & lpProgItem->mask)
  144. {
  145. if (lpProgItem->dwStatusType > SYNCMGRSTATUS_RESUMING)
  146. {
  147. AssertSz(0,"Unknown StatusType passed to Progress");
  148. return FALSE;
  149. }
  150. }
  151. }
  152. __except(EXCEPTION_EXECUTE_HANDLER)
  153. {
  154. AssertSz(0,"Bogus, non-NULL LPSYNCMGRPROGRESSITEM pointer.");
  155. return FALSE;
  156. }
  157. return TRUE;
  158. }
  159. //+---------------------------------------------------------------------------
  160. //
  161. // Function: IsValidSyncLogErrorInfo, private
  162. //
  163. // Synopsis: Determines if the ErrorInfomation is valid,
  164. //
  165. // Arguments: [lpLogError] - Pointer to LogError structure to validate.
  166. //
  167. // Returns: Returns true is the structure is valid.
  168. //
  169. // Modifies:
  170. //
  171. // History: 17-Nov-97 rogerg Created.
  172. //
  173. //----------------------------------------------------------------------------
  174. #define SYNCMGRLOGERROR_VALIDMASK (SYNCMGRLOGERROR_ERRORFLAGS | SYNCMGRLOGERROR_ERRORID | SYNCMGRLOGERROR_ITEMID)
  175. #define SYNCMGRERRROFLAG_MASK (SYNCMGRERRORFLAG_ENABLEJUMPTEXT)
  176. BOOL IsValidSyncLogErrorInfo(DWORD dwErrorLevel,const WCHAR *lpcErrorText,
  177. LPSYNCMGRLOGERRORINFO lpSyncLogError)
  178. {
  179. if (SYNCMGRLOGLEVEL_ERROR < dwErrorLevel)
  180. {
  181. AssertSz(0,"Invalid ErrorLevel");
  182. return FALSE;
  183. }
  184. // must provide error text
  185. if (NULL == lpcErrorText)
  186. {
  187. AssertSz(0,"Invalid ErrorText");
  188. return FALSE;
  189. }
  190. // Optional to have the LogError information.
  191. __try
  192. {
  193. if (lpSyncLogError)
  194. {
  195. if (lpSyncLogError->cbSize != sizeof(SYNCMGRLOGERRORINFO))
  196. {
  197. AssertSz(0,"Unknown LogError cbSize");
  198. return FALSE;
  199. }
  200. if (0 != (lpSyncLogError->mask & ~(SYNCMGRLOGERROR_VALIDMASK)) )
  201. {
  202. AssertSz(0,"Invalid LogError Mask");
  203. return FALSE;
  204. }
  205. if (lpSyncLogError->mask & SYNCMGRLOGERROR_ERRORFLAGS)
  206. {
  207. if (0 != (~(SYNCMGRERRROFLAG_MASK) & lpSyncLogError->dwSyncMgrErrorFlags))
  208. {
  209. AssertSz(0,"Invalid LogError ErrorFlags");
  210. return FALSE;
  211. }
  212. }
  213. }
  214. }
  215. __except(EXCEPTION_EXECUTE_HANDLER)
  216. {
  217. AssertSz(0,"Bogus, non-NULL LPSYNCMGRLOGERRORINFO pointer.");
  218. return FALSE;
  219. }
  220. return TRUE;
  221. }