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.

109 lines
2.4 KiB

  1. /*
  2. * VALIDATE.C
  3. *
  4. * RSM Service : Handle validation code
  5. *
  6. * Author: ErvinP
  7. *
  8. * (c) 2001 Microsoft Corporation
  9. *
  10. */
  11. #include <windows.h>
  12. #include <stdlib.h>
  13. #include <wtypes.h>
  14. #include <ntmsapi.h>
  15. #include "internal.h"
  16. #include "resource.h"
  17. #include "debug.h"
  18. #pragma optimize("agpswy", off)
  19. BOOL ValidateSessionHandle(HANDLE hSession)
  20. {
  21. BOOL ok;
  22. /*
  23. * The server runs in its own context.
  24. * So just need to validate:
  25. * (1) its our context (we can write to it), and
  26. * (2) its a session context (not another one of our contexts)
  27. */
  28. __try {
  29. SESSION *s = (SESSION *)hSession;
  30. ok = (s->sig == SESSION_SIG);
  31. }
  32. __except (EXCEPTION_EXECUTE_HANDLER){
  33. DWORD exceptionCode = GetExceptionCode();
  34. ok = FALSE;
  35. DBGERR(("invalid session handle (%xh) (code=%xh)", hSession, exceptionCode));
  36. }
  37. return ok;
  38. }
  39. #pragma optimize("agpswy", on) // BUGBUG - how to set back to 'default' ?
  40. #pragma optimize("agpswy", off)
  41. BOOL ValidateWStr(LPCWSTR ws)
  42. {
  43. BOOL ok;
  44. __try {
  45. while (*ws++);
  46. ok = TRUE;
  47. }
  48. __except (EXCEPTION_EXECUTE_HANDLER){
  49. DWORD exceptionCode = GetExceptionCode();
  50. ok = FALSE;
  51. DBGERR(("invalid string arg (code=%xh)", exceptionCode));
  52. }
  53. return ok;
  54. }
  55. #pragma optimize("agpswy", on) // BUGBUG - how to set back to 'default' ?
  56. #pragma optimize("agpswy", off)
  57. BOOL ValidateAStr(LPCSTR s)
  58. {
  59. BOOL ok;
  60. __try {
  61. while (*s++);
  62. ok = TRUE;
  63. }
  64. __except (EXCEPTION_EXECUTE_HANDLER){
  65. DWORD exceptionCode = GetExceptionCode();
  66. ok = FALSE;
  67. DBGERR(("invalid string arg (code=%xh)", exceptionCode));
  68. }
  69. return ok;
  70. }
  71. #pragma optimize("agpswy", on) // BUGBUG - how to set back to 'default' ?
  72. #pragma optimize("agpswy", off)
  73. BOOL ValidateBuffer(PVOID buf, ULONG len)
  74. {
  75. PUCHAR bufPtr = (PUCHAR) buf;
  76. BOOL ok;
  77. __try {
  78. while (len > 0){
  79. *bufPtr = *bufPtr;
  80. }
  81. ok = TRUE;
  82. }
  83. __except (EXCEPTION_EXECUTE_HANDLER){
  84. DWORD exceptionCode = GetExceptionCode();
  85. ok = FALSE;
  86. DBGERR(("invalid buffer (code=%xh)", exceptionCode));
  87. }
  88. return ok;
  89. }
  90. #pragma optimize("agpswy", on) // BUGBUG - how to set back to 'default' ?