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.

311 lines
5.3 KiB

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