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.

105 lines
2.2 KiB

  1. #include "stdafx.h"
  2. #include "strutil.h"
  3. BOOL IsValidX500Chars(CString csStringToCheck)
  4. {
  5. BOOL iReturn = TRUE;
  6. if (csStringToCheck.IsEmpty())
  7. {
  8. goto IsValidX500Chars_Exit;
  9. }
  10. // check if the string has any special chars
  11. if (csStringToCheck.FindOneOf(_T(",=+<>#;\r\n")) != -1)
  12. {
  13. iReturn = FALSE;
  14. goto IsValidX500Chars_Exit;
  15. }
  16. IsValidX500Chars_Exit:
  17. return iReturn;
  18. }
  19. BOOL IsValidPath(LPCTSTR lpFileName)
  20. {
  21. while ((*lpFileName != _T('?'))
  22. && (*lpFileName != _T('*'))
  23. && (*lpFileName != _T('"'))
  24. && (*lpFileName != _T('<'))
  25. && (*lpFileName != _T('>'))
  26. && (*lpFileName != _T('|'))
  27. && (*lpFileName != _T('/'))
  28. && (*lpFileName != _T(','))
  29. && (*lpFileName != _T('\0')))
  30. lpFileName++;
  31. if (*lpFileName != '\0')
  32. return FALSE;
  33. return TRUE;
  34. }
  35. BOOL IsValidName(LPCTSTR lpFileName)
  36. {
  37. while ((*lpFileName != _T('?'))
  38. && (*lpFileName != _T('\\'))
  39. && (*lpFileName != _T('*'))
  40. && (*lpFileName != _T('"'))
  41. && (*lpFileName != _T('<'))
  42. && (*lpFileName != _T('>'))
  43. && (*lpFileName != _T('|'))
  44. && (*lpFileName != _T('/'))
  45. && (*lpFileName != _T(':'))
  46. && (*lpFileName != _T('\0')))
  47. lpFileName++;
  48. if (*lpFileName != '\0')
  49. return FALSE;
  50. return TRUE;
  51. }
  52. BOOL IsValidPathFileName(LPCTSTR lpFileName)
  53. {
  54. BOOL bReturn = TRUE;
  55. TCHAR szDrive_only[_MAX_DRIVE];
  56. TCHAR szPath_only[_MAX_PATH];
  57. TCHAR szFilename_only[_MAX_FNAME];
  58. TCHAR szFilename_ext_only[_MAX_EXT];
  59. _tsplitpath(lpFileName, szDrive_only, szPath_only, szFilename_only, szFilename_ext_only);
  60. if (FALSE == IsValidName(szFilename_only))
  61. {
  62. bReturn = FALSE;
  63. }
  64. if (FALSE == IsValidPath(szFilename_only))
  65. {
  66. bReturn = FALSE;
  67. }
  68. if (FALSE == IsValidPath(szPath_only))
  69. {
  70. bReturn = FALSE;
  71. }
  72. return bReturn;
  73. }
  74. BOOL IsValidPort(LPCTSTR str)
  75. {
  76. if (0 == _tcscmp(str,_T("0")))
  77. {
  78. return FALSE;
  79. }
  80. if (*str == '\0') return FALSE;
  81. //if (*str == '-') str++;
  82. while( *str >= '0' && *str <= '9' )
  83. {
  84. str++;
  85. }
  86. return !*str;
  87. }