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.

89 lines
1.6 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. util.c
  5. Abstract:
  6. Contains miscellaneous utility functions used by the Service
  7. Controller:
  8. ScIsValidServiceName
  9. Author:
  10. Rita Wong (ritaw) 15-Mar-1992
  11. Environment:
  12. User Mode -Win32
  13. Revision History:
  14. 11-Apr-1992 JohnRo
  15. Added an assertion check.
  16. Include <sclib.h> so compiler checks prototypes.
  17. 20-May-1992 JohnRo
  18. winsvc.h and related file cleanup.
  19. --*/
  20. #include <stdlib.h>
  21. #include <nt.h>
  22. #include <ntrtl.h>
  23. #include <nturtl.h>
  24. #include <windef.h>
  25. #include <scdebug.h> // SC_ASSERT().
  26. #include <sclib.h> // My prototype.
  27. #include <valid.h> // MAX_SERVICE_NAME_LENGTH
  28. BOOL
  29. ScIsValidServiceName(
  30. IN LPCWSTR ServiceName
  31. )
  32. /*++
  33. Routine Description:
  34. This function validates a given service name. The name length
  35. cannot be greater than 256 characters, and must not contain any
  36. forward-slash, or back-slash.
  37. Arguments:
  38. ServiceName - Supplies the service name to be validated.
  39. Return Value:
  40. TRUE - The name is valid.
  41. FALSE - The name is invalid.
  42. --*/
  43. {
  44. LPCWSTR IllegalChars = L"\\/";
  45. DWORD NameLength;
  46. SC_ASSERT( ServiceName != NULL ); // Avoid memory access fault in wcslen().
  47. if (*ServiceName == 0) {
  48. return FALSE;
  49. }
  50. if ((NameLength = (DWORD) wcslen(ServiceName)) > MAX_SERVICE_NAME_LENGTH) {
  51. return FALSE;
  52. }
  53. if (wcscspn(ServiceName, IllegalChars) < NameLength) {
  54. return FALSE;
  55. }
  56. return TRUE;
  57. }