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.

129 lines
3.0 KiB

  1. //=============================================================================
  2. //
  3. // MODULE: ASN1GTime.cxx
  4. //
  5. // Description:
  6. //
  7. // Implementation of ASN.1 generalized time parsing logic
  8. //
  9. // Modification History
  10. //
  11. // Mark Pustilnik Date: 06/12/02 - created
  12. //
  13. //=============================================================================
  14. #include "ASN1Parser.hxx"
  15. #include <stdio.h>
  16. //
  17. // Retrieve the value of an ASN.1-encoded generalized time
  18. // Times are converted to 'SYSTEMTIME' format for ease of handling by Netmon
  19. //
  20. DWORD
  21. ASN1ParserGeneralizedTime::GetValue(
  22. IN OUT ASN1FRAME * Frame,
  23. OUT ASN1VALUE * Value
  24. )
  25. {
  26. DWORD dw;
  27. ASN1FRAME FrameIn = *Frame;
  28. DWORD DLength = DataLength( Frame );
  29. ULPBYTE Address = Frame->Address;
  30. if ( *Frame->Address != BuildDescriptor(
  31. ctUniversal,
  32. pcPrimitive,
  33. (BYTE)utGeneralizedTime ))
  34. {
  35. dw = ERROR_INVALID_USER_BUFFER;
  36. goto Cleanup;
  37. }
  38. //
  39. // Skip over the the descriptor
  40. //
  41. Address++;
  42. //
  43. // Skip over the length header
  44. //
  45. Address += HeaderLength( Address );
  46. Value->Address = Address;
  47. Value->Length = DLength;
  48. Value->ut = utGeneralizedTime;
  49. RtlZeroMemory( &Value->st, sizeof( Value->st ));
  50. //
  51. // Length should be 0xF for regular ZULU time encoding
  52. //
  53. if ( DLength == 0xF )
  54. {
  55. //
  56. // Time is encoded as 20370913024805Z
  57. // where year = 2037
  58. // month = 09
  59. // day = 13
  60. // hour = 02
  61. // minute = 48
  62. // second = 05
  63. // Z = zulu time
  64. //
  65. if ( 6 != sscanf(
  66. (const char * )Value->Address,
  67. "%04d%02d%02d%02d%02d%02d",
  68. &Value->st.wYear,
  69. &Value->st.wMonth,
  70. &Value->st.wDay,
  71. &Value->st.wHour,
  72. &Value->st.wMinute,
  73. &Value->st.wSecond
  74. ))
  75. {
  76. //
  77. // Expected to parse out 6 fields
  78. //
  79. dw = ERROR_INVALID_TIME;
  80. goto Cleanup;
  81. }
  82. Address += DLength;
  83. //
  84. // TODO: add handling for non-Zulu times
  85. //
  86. //
  87. // Cheap hack: convert to filetime and back in order to get the day of
  88. // week to display correctly
  89. //
  90. FILETIME ft;
  91. SystemTimeToFileTime( &Value->st, &ft );
  92. FileTimeToSystemTime( &ft, &Value->st );
  93. }
  94. else
  95. {
  96. dw = ERROR_INVALID_TIME;
  97. goto Cleanup;
  98. }
  99. Frame->Address = Address;
  100. dw = ERROR_SUCCESS;
  101. Cleanup:
  102. if ( dw != ERROR_SUCCESS )
  103. {
  104. *Frame = FrameIn;
  105. }
  106. return dw;
  107. }