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.

259 lines
6.6 KiB

  1. /*++
  2. Copyright (c) 1991-1993 Microsoft Corporation
  3. Module Name:
  4. ApiTime.c
  5. Abstract:
  6. This module contains individual API handler for the NetRemoteTOD API.
  7. SUPPORTED : NetRemoteTOD.
  8. Author:
  9. Shanku Niyogi (w-shanku) 04-Apr-1991
  10. Revision History:
  11. 10-Jun-1993 JohnRo
  12. RAID 13081: NetRemoteTOD should return timezone info.
  13. --*/
  14. #include "XactSrvP.h"
  15. #include <timelib.h> // NetpLocalTimeZoneOffset().
  16. //
  17. // Forward declarations
  18. //
  19. NET_API_STATUS
  20. GetLocalTOD(
  21. OUT LPTIME_OF_DAY_INFO TimeOfDayInfo
  22. );
  23. //
  24. // Declaration of descriptor strings.
  25. //
  26. STATIC const LPDESC Desc16_time_of_day_info = REM16_time_of_day_info;
  27. STATIC const LPDESC Desc32_time_of_day_info = REM32_time_of_day_info;
  28. NTSTATUS
  29. XsNetRemoteTOD (
  30. API_HANDLER_PARAMETERS
  31. )
  32. /*++
  33. Routine Description:
  34. This routine handles a call to NetRemoteTOD.
  35. Arguments:
  36. API_HANDLER_PARAMETERS - information about the API call. See
  37. XsTypes.h for details.
  38. Return Value:
  39. NTSTATUS - STATUS_SUCCESS or reason for failure.
  40. --*/
  41. {
  42. NET_API_STATUS status;
  43. PXS_NET_REMOTE_TOD parameters = Parameters;
  44. TIME_OF_DAY_INFO timeOfDay;
  45. DWORD bytesRequired = 0; // Conversion variables
  46. LPBYTE stringLocation = NULL;
  47. API_HANDLER_PARAMETERS_REFERENCE; // Avoid warnings
  48. IF_DEBUG(TIME) {
  49. NetpKdPrint(( "XsNetRemoteTOD: header at %lx, params at %lx\n",
  50. Header, parameters ));
  51. }
  52. //
  53. // Make the local call.
  54. //
  55. status = GetLocalTOD(
  56. &timeOfDay
  57. );
  58. try {
  59. if ( !XsApiSuccess( status )) {
  60. IF_DEBUG(API_ERRORS) {
  61. NetpKdPrint(( "XsNetRemoteTOD: NetRemoteTOD failed: "
  62. "%X\n", status ));
  63. }
  64. Header->Status = (WORD)status;
  65. goto cleanup;
  66. }
  67. //
  68. // Convert the structure returned by the 32-bit call to a 16-bit
  69. // structure. The last possible location for variable data is
  70. // calculated from buffer location and length.
  71. //
  72. stringLocation = (LPBYTE)( XsSmbGetPointer( &parameters->Buffer )
  73. + SmbGetUshort( &parameters->BufLen ) );
  74. status = RapConvertSingleEntry(
  75. (LPBYTE)&timeOfDay,
  76. Desc32_time_of_day_info,
  77. FALSE,
  78. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  79. (LPBYTE)XsSmbGetPointer( &parameters->Buffer ),
  80. Desc16_time_of_day_info,
  81. TRUE,
  82. &stringLocation,
  83. &bytesRequired,
  84. Response,
  85. NativeToRap
  86. );
  87. if ( status != NERR_Success ) {
  88. IF_DEBUG(ERRORS) {
  89. NetpKdPrint(( "XsNetRemoteTOD: RapConvertSingleEntry failed: "
  90. "%X\n", status ));
  91. }
  92. Header->Status = NERR_InternalError;
  93. goto cleanup;
  94. }
  95. IF_DEBUG(TIME) {
  96. NetpKdPrint(( "32-bit data at %lx, 16-bit data at %lx, %ld BR\n",
  97. &timeOfDay, SmbGetUlong( &parameters->Buffer ),
  98. bytesRequired ));
  99. }
  100. //
  101. // Determine return code based on the size of the buffer. There is
  102. // no variable data for a time_of_day_info structure, only fixed data.
  103. //
  104. if ( !XsCheckBufferSize(
  105. SmbGetUshort( &parameters->BufLen ),
  106. Desc16_time_of_day_info,
  107. FALSE // not in native format
  108. )) {
  109. IF_DEBUG(ERRORS) {
  110. NetpKdPrint(( "XsNetRemoteTOD: Buffer too small.\n" ));
  111. }
  112. Header->Status = NERR_BufTooSmall;
  113. }
  114. //
  115. // No return parameters.
  116. //
  117. cleanup:
  118. ;
  119. } except( EXCEPTION_EXECUTE_HANDLER ) {
  120. Header->Status = (WORD)RtlNtStatusToDosError( GetExceptionCode() );
  121. }
  122. //
  123. // Determine return buffer size.
  124. //
  125. XsSetDataCount(
  126. &parameters->BufLen,
  127. Desc16_time_of_day_info,
  128. Header->Converter,
  129. 1,
  130. Header->Status
  131. );
  132. return STATUS_SUCCESS;
  133. } // XsNetRemoteTOD
  134. NET_API_STATUS
  135. GetLocalTOD(
  136. OUT LPTIME_OF_DAY_INFO TimeOfDayInfo
  137. )
  138. /*++
  139. Routine Description:
  140. This routine calls the Win32 and NT base timer APIs to get the
  141. relevant time/date information. It also calls the Rtl routine to
  142. convert the time elapsed since 1-1-1970.
  143. The routine allocates a buffer to contain the time of day information
  144. and returns a pointer to that buffer to the caller.
  145. Arguments:
  146. bufptr - Location of where to place pointer to buffer.
  147. Return Value:
  148. NTSTATUS - STATUS_SUCCESS or reason for failure.
  149. --*/
  150. {
  151. SYSTEMTIME LocalTime;
  152. LONG LocalTimeZoneOffsetSecs; // offset (+ for West of GMT, etc).
  153. LARGE_INTEGER Time;
  154. //
  155. // Call the appropriate routines to collect the time information
  156. //
  157. // Number of seconds from UTC. Positive values for west of Greenwich,
  158. // negative values for east of Greenwich.
  159. LocalTimeZoneOffsetSecs = NetpLocalTimeZoneOffset();
  160. GetLocalTime(&LocalTime);
  161. TimeOfDayInfo->tod_hours = LocalTime.wHour;
  162. TimeOfDayInfo->tod_mins = LocalTime.wMinute;
  163. TimeOfDayInfo->tod_secs = LocalTime.wSecond;
  164. TimeOfDayInfo->tod_hunds = LocalTime.wMilliseconds/10;
  165. // tod_timezone is + for west of GMT, - for east of it.
  166. // tod_timezone is in minutes.
  167. TimeOfDayInfo->tod_timezone = LocalTimeZoneOffsetSecs / 60;
  168. TimeOfDayInfo->tod_tinterval = 310;
  169. TimeOfDayInfo->tod_day = LocalTime.wDay;
  170. TimeOfDayInfo->tod_month = LocalTime.wMonth;
  171. TimeOfDayInfo->tod_year = LocalTime.wYear;
  172. TimeOfDayInfo->tod_weekday = LocalTime.wDayOfWeek;
  173. //
  174. // Get the 64-bit system time. Convert the system time to the
  175. // number of seconds since 1-1-1970. This is in GMT, Rap will
  176. // convert this to local time later.
  177. //
  178. NtQuerySystemTime(&Time);
  179. RtlTimeToSecondsSince1970(
  180. &Time,
  181. &(TimeOfDayInfo->tod_elapsedt)
  182. );
  183. //
  184. // Get the free running counter value
  185. //
  186. TimeOfDayInfo->tod_msecs = GetTickCount();
  187. return(NO_ERROR);
  188. }