Source code of Windows XP (NT5)
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.

298 lines
5.4 KiB

  1. /*
  2. * valid.c - Validation functions module.
  3. */
  4. /* Headers
  5. **********/
  6. #include "project.h"
  7. #pragma hdrstop
  8. /****************************** Public Functions *****************************/
  9. PUBLIC_CODE BOOL IsValidHWND(HWND hwnd)
  10. {
  11. /* Ask User if this is a valid window. */
  12. return(IsWindow(hwnd));
  13. }
  14. #ifdef DEBUG
  15. PUBLIC_CODE BOOL IsValidHANDLE(HANDLE hnd)
  16. {
  17. return(EVAL(hnd != INVALID_HANDLE_VALUE));
  18. }
  19. PUBLIC_CODE BOOL IsValidHEVENT(HANDLE hevent)
  20. {
  21. return(IsValidHANDLE(hevent));
  22. }
  23. PUBLIC_CODE BOOL IsValidHFILE(HANDLE hf)
  24. {
  25. return(IsValidHANDLE(hf));
  26. }
  27. PUBLIC_CODE BOOL IsValidHGLOBAL(HGLOBAL hg)
  28. {
  29. return(IsValidHANDLE(hg));
  30. }
  31. PUBLIC_CODE BOOL IsValidHMENU(HMENU hmenu)
  32. {
  33. return(IsValidHANDLE(hmenu));
  34. }
  35. PUBLIC_CODE BOOL IsValidHINSTANCE(HINSTANCE hinst)
  36. {
  37. return(IsValidHANDLE(hinst));
  38. }
  39. PUBLIC_CODE BOOL IsValidHICON(HICON hicon)
  40. {
  41. return(IsValidHANDLE(hicon));
  42. }
  43. PUBLIC_CODE BOOL IsValidHKEY(HKEY hkey)
  44. {
  45. return(IsValidHANDLE(hkey));
  46. }
  47. PUBLIC_CODE BOOL IsValidHMODULE(HMODULE hmod)
  48. {
  49. return(IsValidHANDLE(hmod));
  50. }
  51. PUBLIC_CODE BOOL IsValidHPROCESS(HANDLE hprocess)
  52. {
  53. return(IsValidHANDLE(hprocess));
  54. }
  55. PUBLIC_CODE BOOL IsValidPCSECURITY_ATTRIBUTES(PCSECURITY_ATTRIBUTES pcsa)
  56. {
  57. /* FEATURE: Fill me in. */
  58. return(IS_VALID_READ_PTR(pcsa, CSECURITY_ATTRIBUTES));
  59. }
  60. PUBLIC_CODE BOOL IsValidFileCreationMode(DWORD dwMode)
  61. {
  62. BOOL bResult;
  63. switch (dwMode)
  64. {
  65. case CREATE_NEW:
  66. case CREATE_ALWAYS:
  67. case OPEN_EXISTING:
  68. case OPEN_ALWAYS:
  69. case TRUNCATE_EXISTING:
  70. bResult = TRUE;
  71. break;
  72. default:
  73. bResult = FALSE;
  74. ERROR_OUT(("IsValidFileCreationMode(): Invalid file creation mode %#lx.",
  75. dwMode));
  76. break;
  77. }
  78. return(bResult);
  79. }
  80. PUBLIC_CODE BOOL IsValidHTEMPLATEFILE(HANDLE htf)
  81. {
  82. return(IsValidHANDLE(htf));
  83. }
  84. PUBLIC_CODE BOOL IsValidPCFILETIME(PCFILETIME pcft)
  85. {
  86. /* dwLowDateTime may be any value. */
  87. /* dwHighDateTime may be any value. */
  88. return(IS_VALID_READ_PTR(pcft, CFILETIME));
  89. }
  90. PUBLIC_CODE BOOL IsValidPCPOINT(PCPOINT pcpt)
  91. {
  92. /* x may be any value. */
  93. /* y may be any value. */
  94. return(IS_VALID_READ_PTR(pcpt, CPOINT));
  95. }
  96. PUBLIC_CODE BOOL IsValidPCPOINTL(PCPOINTL pcptl)
  97. {
  98. /* x may be any value. */
  99. /* y may be any value. */
  100. return(IS_VALID_READ_PTR(pcptl, CPOINTL));
  101. }
  102. PUBLIC_CODE BOOL IsValidPCWIN32_FIND_DATA(PCWIN32_FIND_DATA pcwfd)
  103. {
  104. /* FEATURE: Fill me in. */
  105. return(IS_VALID_READ_PTR(pcwfd, CWIN32_FIND_DATA));
  106. }
  107. PUBLIC_CODE BOOL IsValidShowCmd(int nShow)
  108. {
  109. BOOL bResult;
  110. switch (nShow)
  111. {
  112. case SW_HIDE:
  113. case SW_SHOWNORMAL:
  114. case SW_SHOWMINIMIZED:
  115. case SW_SHOWMAXIMIZED:
  116. case SW_SHOWNOACTIVATE:
  117. case SW_SHOW:
  118. case SW_MINIMIZE:
  119. case SW_SHOWMINNOACTIVE:
  120. case SW_SHOWNA:
  121. case SW_RESTORE:
  122. case SW_SHOWDEFAULT:
  123. bResult = TRUE;
  124. break;
  125. default:
  126. bResult = FALSE;
  127. ERROR_OUT(("IsValidShowCmd(): Invalid show command %d.",
  128. nShow));
  129. break;
  130. }
  131. return(bResult);
  132. }
  133. PUBLIC_CODE BOOL IsValidPath(PCSTR pcszPath)
  134. {
  135. /* FEATURE: Beef up path validation. */
  136. return(IS_VALID_STRING_PTR(pcszPath, CSTR) &&
  137. EVAL((UINT)lstrlen(pcszPath) < MAX_PATH_LEN));
  138. }
  139. PUBLIC_CODE BOOL IsValidPathResult(HRESULT hr, PCSTR pcszPath,
  140. UINT ucbPathBufLen)
  141. {
  142. return((hr == S_OK &&
  143. EVAL(IsValidPath(pcszPath)) &&
  144. EVAL((UINT)lstrlen(pcszPath) < ucbPathBufLen)) ||
  145. (hr != S_OK &&
  146. EVAL(! ucbPathBufLen ||
  147. ! pcszPath ||
  148. ! *pcszPath)));
  149. }
  150. PUBLIC_CODE BOOL IsValidExtension(PCSTR pcszExt)
  151. {
  152. return(IS_VALID_STRING_PTR(pcszExt, CSTR) &&
  153. EVAL(lstrlen(pcszExt) < MAX_PATH_LEN) &&
  154. EVAL(*pcszExt == PERIOD));
  155. }
  156. PUBLIC_CODE BOOL IsValidIconIndex(HRESULT hr, PCSTR pcszIconFile,
  157. UINT ucbIconFileBufLen, int niIcon)
  158. {
  159. return(EVAL(IsValidPathResult(hr, pcszIconFile, ucbIconFileBufLen)) &&
  160. EVAL(hr == S_OK ||
  161. ! niIcon));
  162. }
  163. PUBLIC_CODE BOOL IsValidRegistryValueType(DWORD dwType)
  164. {
  165. BOOL bResult;
  166. switch (dwType)
  167. {
  168. case REG_NONE:
  169. case REG_SZ:
  170. case REG_EXPAND_SZ:
  171. case REG_BINARY:
  172. case REG_DWORD:
  173. case REG_DWORD_BIG_ENDIAN:
  174. case REG_LINK:
  175. case REG_MULTI_SZ:
  176. case REG_RESOURCE_LIST:
  177. case REG_FULL_RESOURCE_DESCRIPTOR:
  178. case REG_RESOURCE_REQUIREMENTS_LIST:
  179. bResult = TRUE;
  180. break;
  181. default:
  182. bResult = FALSE;
  183. ERROR_OUT(("IsValidRegistryValueType(): Invalid registry value type %lu.",
  184. dwType));
  185. break;
  186. }
  187. return(bResult);
  188. }
  189. PUBLIC_CODE BOOL IsValidHotkey(WORD wHotkey)
  190. {
  191. /* FEATURE: Beef up hotkey validation. */
  192. return(wHotkey != 0);
  193. }
  194. #ifdef _COMPARISONRESULT_DEFINED_
  195. PUBLIC_CODE BOOL IsValidCOMPARISONRESULT(COMPARISONRESULT cr)
  196. {
  197. BOOL bResult;
  198. switch (cr)
  199. {
  200. case CR_FIRST_SMALLER:
  201. case CR_EQUAL:
  202. case CR_FIRST_LARGER:
  203. bResult = TRUE;
  204. break;
  205. default:
  206. WARNING_OUT(("IsValidCOMPARISONRESULT(): Unknown COMPARISONRESULT %d.",
  207. cr));
  208. bResult = FALSE;
  209. break;
  210. }
  211. return(bResult);
  212. }
  213. #endif /* _COMPARISONRESULT_DEFINED_ */
  214. #endif /* DEBUG */