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.

135 lines
2.5 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. valid.c
  5. Abstract:
  6. Contains validation routines for service controller parameters.
  7. Author:
  8. Dan Lafferty (danl) 29-Mar-1992
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. 29-Mar-1992 danl
  13. Created
  14. 10-Apr-1992 JohnRo
  15. Include <valid.h> so compiler checks prototypes.
  16. --*/
  17. //
  18. // INCLUDES
  19. //
  20. #include <nt.h>
  21. #include <ntrtl.h> // DbgPrint prototype
  22. #include <nturtl.h> // needed for winbase.h when ntrtl is present
  23. #include <windows.h> // CRITICAL_SECTION
  24. #include <scdebug.h> // SC_LOG
  25. #include <winsvc.h> // SERVICE_STATUS
  26. #include <valid.h> // My prototypes.
  27. BOOL
  28. ScCurrentStateInvalid(
  29. DWORD dwCurrentState
  30. )
  31. /*++
  32. Routine Description:
  33. This function returns TRUE if the CurrentState is invalid.
  34. Otherwise FALSE is returned.
  35. Arguments:
  36. dwCurrentState - This is the ServiceState that is being validiated.
  37. Return Value:
  38. TRUE - The CurrentState is invalid.
  39. FALSE - The CurrentState is valid.
  40. Note:
  41. --*/
  42. {
  43. if ((dwCurrentState == SERVICE_STOPPED) ||
  44. (dwCurrentState == SERVICE_START_PENDING) ||
  45. (dwCurrentState == SERVICE_STOP_PENDING) ||
  46. (dwCurrentState == SERVICE_RUNNING) ||
  47. (dwCurrentState == SERVICE_CONTINUE_PENDING) ||
  48. (dwCurrentState == SERVICE_PAUSE_PENDING) ||
  49. (dwCurrentState == SERVICE_PAUSED )) {
  50. return(FALSE);
  51. }
  52. return(TRUE);
  53. }
  54. DWORD
  55. ScValidateMultiSZ(
  56. LPCWSTR lpStrings,
  57. DWORD cbStrings
  58. )
  59. /*++
  60. Routine Description:
  61. This function takes a MULTI_SZ value read in from the registry or
  62. passed in via RPC and validates it.
  63. Arguments:
  64. Return Value:
  65. --*/
  66. {
  67. DWORD dwLastChar;
  68. //
  69. // Make sure the MULTI_SZ is well-formed. As long as it is properly
  70. // double NULL terminated, things should be ok.
  71. //
  72. if ((cbStrings % 2) ||
  73. (cbStrings < sizeof(WCHAR)*2)) {
  74. //
  75. // There's an odd number of bytes, this can't be well-formed
  76. //
  77. return ERROR_INVALID_PARAMETER;
  78. }
  79. dwLastChar = (cbStrings / sizeof(WCHAR)) - 1;
  80. if ((lpStrings[dwLastChar] != L'\0') ||
  81. (lpStrings[dwLastChar - 1] != L'\0')) {
  82. //
  83. // The buffer is not double-NUL terminated
  84. //
  85. return ERROR_INVALID_PARAMETER;
  86. }
  87. return NO_ERROR;
  88. }