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.

199 lines
5.1 KiB

  1. /*++
  2. Copyright (c) 1991-1993 Microsoft Corporation
  3. Module Name:
  4. tod.c
  5. Abstract:
  6. This module contains the server end of the NetRemoteTOD API.
  7. Author:
  8. Rajen Shah (rajens) 02-Apr-1991
  9. [Environment:]
  10. User Mode - Mixed NT and Win32
  11. Revision History:
  12. 02-Apr-1991 RajenS
  13. Created
  14. 02-Mar-1992 JohnRo
  15. Disable DbgPrints for normal APIs (caused loss of elapsed time!)
  16. 08-Apr-1992 ChuckL
  17. Moved into server service
  18. 10-Jun-1993 JohnRo
  19. RAID 13081: NetRemoteTOD should return timezone info.
  20. 16-Jun-1993 JohnRo
  21. RAID 13080: Fix GP fault if MIDL_user_allocate returns NULL ptr or
  22. caller passes us NULL ptr.
  23. --*/
  24. #include <nt.h>
  25. #include <ntrtl.h>
  26. #include <nturtl.h>
  27. #include <windows.h>
  28. #include <lmcons.h>
  29. #include <netlibnt.h>
  30. #include <lmremutl.h>
  31. #include <rpcutil.h>
  32. #include <ssdebug.h> // SS_PRINT() macro.
  33. #include <timelib.h>
  34. #define TOD_DEFAULT_INTERVAL 310 // 310-milisecond interval
  35. NTSTATUS
  36. timesvc_RemoteTimeOfDay(
  37. OUT LPTIME_OF_DAY_INFO *lpTimeOfDayInfo
  38. )
  39. /*++
  40. Routine Description:
  41. This routine calls the Win32 and NT base timer APIs to get the
  42. relevant time/date information. It also calls the Rtl routine to
  43. convert the time elapsed since 1-1-1970.
  44. The routine allocates a buffer to contain the time of day information
  45. and returns a pointer to that buffer to the caller.
  46. Arguments:
  47. lpTimeOfDayInfo - Location of where to place pointer to buffer.
  48. Return Value:
  49. NTSTATUS - STATUS_SUCCESS or reason for failure.
  50. --*/
  51. {
  52. SYSTEMTIME SystemTime;
  53. LARGE_INTEGER Time;
  54. DWORD TickCount;
  55. LPTIME_OF_DAY_INFO lpTimeOfDay;
  56. LONG LocalTimeZoneOffsetSecs; // offset (+ for West of GMT, etc).
  57. if (lpTimeOfDayInfo == NULL) {
  58. return (STATUS_INVALID_PARAMETER);
  59. }
  60. //
  61. // Call the appropriate routines to collect the time information
  62. //
  63. GetSystemTime(&SystemTime);
  64. //
  65. // Get number of seconds from UTC. Positive values for west of Greenwich,
  66. // negative values for east of Greenwich.
  67. //
  68. LocalTimeZoneOffsetSecs = NetpLocalTimeZoneOffset();
  69. //
  70. // Allocate a TimeOfDay_INFO structure that is to be returned to the
  71. // caller and fill it with the relevant data.
  72. //
  73. *lpTimeOfDayInfo = (TIME_OF_DAY_INFO *) MIDL_user_allocate(
  74. sizeof (struct _TIME_OF_DAY_INFO)
  75. );
  76. if (*lpTimeOfDayInfo == NULL) {
  77. SS_PRINT((
  78. "SRVSVC: timesvc_RemoteTimeOfDay"
  79. "got NULL from MIDL_user_allocate!\n" ));
  80. return(STATUS_NO_MEMORY);
  81. }
  82. lpTimeOfDay = (LPTIME_OF_DAY_INFO)(*lpTimeOfDayInfo);
  83. lpTimeOfDay->tod_hours = SystemTime.wHour;
  84. lpTimeOfDay->tod_mins = SystemTime.wMinute;
  85. lpTimeOfDay->tod_secs = SystemTime.wSecond;
  86. lpTimeOfDay->tod_hunds = SystemTime.wMilliseconds/10;
  87. lpTimeOfDay->tod_tinterval = TOD_DEFAULT_INTERVAL;
  88. lpTimeOfDay->tod_day = SystemTime.wDay;
  89. lpTimeOfDay->tod_month = SystemTime.wMonth;
  90. lpTimeOfDay->tod_year = SystemTime.wYear;
  91. lpTimeOfDay->tod_weekday = SystemTime.wDayOfWeek;
  92. // tod_timezone is + for west of GMT, - for east of it.
  93. // tod_timezone is in minutes.
  94. lpTimeOfDay->tod_timezone = LocalTimeZoneOffsetSecs / 60;
  95. // Get the 64-bit system time.
  96. // Convert the system time to the number of miliseconds
  97. // since 1-1-1970.
  98. //
  99. NtQuerySystemTime(&Time);
  100. RtlTimeToSecondsSince1970(&Time,
  101. &(lpTimeOfDay->tod_elapsedt)
  102. );
  103. // Get the free running counter value
  104. //
  105. TickCount = GetTickCount();
  106. lpTimeOfDay->tod_msecs = TickCount;
  107. return(STATUS_SUCCESS);
  108. } // timesvc_RemoteTimeOfDay
  109. NET_API_STATUS
  110. NetrRemoteTOD (
  111. IN LPSTR ServerName,
  112. OUT LPTIME_OF_DAY_INFO *lpTimeOfDayInfo
  113. )
  114. /*++
  115. Routine Description:
  116. This is the RPC server entry point for the NetRemoteTOD API.
  117. Arguments:
  118. ServerName - Name of server on which this API is to be executed.
  119. It should match this server's name - no checking is
  120. done since it is assumed that RPC did the right thing.
  121. lpTimeOfDayInfo - On return takes a pointer to a TIME_OF_DAY_INFO
  122. structure - the memory is allocated here.
  123. Return Value:
  124. Returns a NET_API_STATUS code.
  125. Also returns a pointer to the TIME_OF_DAY_INFO data buffer that was
  126. allocated, if there is no error.
  127. --*/
  128. {
  129. NTSTATUS status;
  130. //
  131. // Call the worker routine to collect all the time/date information
  132. //
  133. status = timesvc_RemoteTimeOfDay(lpTimeOfDayInfo);
  134. //
  135. // Translate the NTSTATUS to a NET_API_STATUS error, and return it.
  136. //
  137. return(NetpNtStatusToApiStatus(status));
  138. UNREFERENCED_PARAMETER( ServerName );
  139. }