Skip to content

Commit bb7a613

Browse files
committed
[SRVSVC][WKSSVC][NET] Improve server and workstation statistics
- Server and Workstation services return proper boot time. - Net formats boot time properly. CORE-19198
1 parent 318a040 commit bb7a613

File tree

5 files changed

+68
-31
lines changed

5 files changed

+68
-31
lines changed

base/applications/network/net/cmdStatistics.c

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ DisplayServerStatistics(VOID)
1818
LARGE_INTEGER LargeValue;
1919
FILETIME FileTime, LocalFileTime;
2020
SYSTEMTIME SystemTime;
21-
WORD wHour;
21+
WCHAR DateBuffer[32], TimeBuffer[32];
2222
INT nPaddedLength = 35;
2323
NET_API_STATUS Status;
2424

@@ -44,21 +44,22 @@ DisplayServerStatistics(VOID)
4444
FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
4545
FileTimeToSystemTime(&LocalFileTime, &SystemTime);
4646

47-
wHour = SystemTime.wHour;
48-
if (wHour == 0)
49-
{
50-
wHour = 12;
51-
}
52-
else if (wHour > 12)
53-
{
54-
wHour = wHour - 12;
55-
}
47+
GetDateFormatW(LOCALE_USER_DEFAULT,
48+
DATE_SHORTDATE,
49+
&SystemTime,
50+
NULL,
51+
DateBuffer,
52+
ARRAYSIZE(DateBuffer));
53+
54+
GetTimeFormatW(LOCALE_USER_DEFAULT,
55+
0,
56+
&SystemTime,
57+
NULL,
58+
TimeBuffer,
59+
ARRAYSIZE(TimeBuffer));
5660

5761
PrintMessageString(4600);
58-
ConPrintf(StdOut, L" %d/%d/%d %d:%02d %s\n\n\n",
59-
SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear,
60-
wHour, SystemTime.wMinute,
61-
(SystemTime.wHour >= 1 && SystemTime.wHour < 13) ? L"AM" : L"PM");
62+
ConPrintf(StdOut, L" %s %s\n\n\n", DateBuffer, TimeBuffer);
6263

6364
PrintPaddedMessageString(4601, nPaddedLength);
6465
ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_sopens);
@@ -131,7 +132,7 @@ DisplayWorkstationStatistics(VOID)
131132
LARGE_INTEGER LargeValue;
132133
FILETIME FileTime, LocalFileTime;
133134
SYSTEMTIME SystemTime;
134-
WORD wHour;
135+
WCHAR DateBuffer[32], TimeBuffer[32];
135136
INT nPaddedLength = 47;
136137
NET_API_STATUS Status;
137138

@@ -142,7 +143,7 @@ DisplayWorkstationStatistics(VOID)
142143
goto done;
143144

144145
Status = NetStatisticsGet(NULL,
145-
SERVICE_SERVER,
146+
SERVICE_WORKSTATION,
146147
0,
147148
0,
148149
(LPBYTE*)&StatisticsInfo);
@@ -159,21 +160,22 @@ DisplayWorkstationStatistics(VOID)
159160
FileTimeToLocalFileTime(&FileTime, &LocalFileTime);
160161
FileTimeToSystemTime(&LocalFileTime, &SystemTime);
161162

162-
wHour = SystemTime.wHour;
163-
if (wHour == 0)
164-
{
165-
wHour = 12;
166-
}
167-
else if (wHour > 12)
168-
{
169-
wHour = wHour - 12;
170-
}
163+
GetDateFormatW(LOCALE_USER_DEFAULT,
164+
DATE_SHORTDATE,
165+
&SystemTime,
166+
NULL,
167+
DateBuffer,
168+
ARRAYSIZE(DateBuffer));
169+
170+
GetTimeFormatW(LOCALE_USER_DEFAULT,
171+
0,
172+
&SystemTime,
173+
NULL,
174+
TimeBuffer,
175+
ARRAYSIZE(TimeBuffer));
171176

172177
PrintMessageString(4600);
173-
ConPrintf(StdOut, L" %d/%d/%d %d:%02d %s\n\n\n",
174-
SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear,
175-
wHour, SystemTime.wMinute,
176-
(SystemTime.wHour >= 1 && SystemTime.wHour < 13) ? L"AM" : L"PM");
178+
ConPrintf(StdOut, L" %s %s\n\n\n", DateBuffer, TimeBuffer);
177179

178180
PrintPaddedMessageString(4630, nPaddedLength);
179181
ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->BytesReceived.QuadPart);

base/services/srvsvc/precomp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <winreg.h>
1111
#include <winsvc.h>
1212
#include <lmserver.h>
13+
#include <ndk/exfuncs.h>
1314

1415
#include <srvsvc_s.h>
1516

base/services/srvsvc/rpcserver.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,9 @@ NetrServerStatisticsGet(
476476
DWORD Options,
477477
LPSTAT_SERVER_0 *InfoStruct)
478478
{
479-
PSTAT_SERVER_0 pStatBuffer;
479+
SYSTEM_TIMEOFDAY_INFORMATION TimeOfDayInfo;
480+
PSTAT_SERVER_0 pStatBuffer = NULL;
481+
NTSTATUS Status;
480482

481483
TRACE("NetrServerStatisticsGet(%p %p %lu 0x%lx %p)\n",
482484
ServerName, Service, Level, Options, InfoStruct);
@@ -493,6 +495,20 @@ NetrServerStatisticsGet(
493495

494496
ZeroMemory(pStatBuffer, sizeof(STAT_SERVER_0));
495497

498+
/* Query the boot time */
499+
Status = NtQuerySystemInformation(SystemTimeOfDayInformation,
500+
&TimeOfDayInfo,
501+
sizeof(TimeOfDayInfo),
502+
NULL);
503+
if (NT_SUCCESS(Status))
504+
{
505+
ULONG Seconds = 0;
506+
if (RtlTimeToSecondsSince1970(&TimeOfDayInfo.BootTime, &Seconds))
507+
{
508+
pStatBuffer->sts0_start = Seconds;
509+
}
510+
}
511+
496512
// FIXME: Return the actual statistcs data!
497513

498514
*InfoStruct = pStatBuffer;

base/services/wkssvc/precomp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <ntsecapi.h>
1818
#include <ntmsv1_0.h>
1919
//#include <ntstatus.h>
20+
#include <ndk/exfuncs.h>
2021
#include <ndk/obfuncs.h>
2122
#include <ndk/psfuncs.h>
2223
#include <ndk/rtlfuncs.h>

base/services/wkssvc/rpcserver.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,9 @@ NetrWorkstationStatisticsGet(
10121012
unsigned long Options,
10131013
LPSTAT_WORKSTATION_0 *Buffer)
10141014
{
1015-
PSTAT_WORKSTATION_0 pStatBuffer;
1015+
SYSTEM_TIMEOFDAY_INFORMATION TimeOfDayInfo;
1016+
PSTAT_WORKSTATION_0 pStatBuffer = NULL;
1017+
NTSTATUS Status;
10161018

10171019
TRACE("NetrWorkstationStatisticsGet(%p %p %lu 0x%lx %p)\n",
10181020
ServerName, ServiceName, Level, Options, Buffer);
@@ -1029,6 +1031,21 @@ NetrWorkstationStatisticsGet(
10291031

10301032
ZeroMemory(pStatBuffer, sizeof(STAT_WORKSTATION_0));
10311033

1034+
/* Query the boot time */
1035+
Status = NtQuerySystemInformation(SystemTimeOfDayInformation,
1036+
&TimeOfDayInfo,
1037+
sizeof(TimeOfDayInfo),
1038+
NULL);
1039+
if (NT_SUCCESS(Status))
1040+
{
1041+
ULONG Seconds = 0;
1042+
if (RtlTimeToSecondsSince1970(&TimeOfDayInfo.BootTime, &Seconds))
1043+
{
1044+
pStatBuffer->StatisticsStartTime.u.HighPart = 0;
1045+
pStatBuffer->StatisticsStartTime.u.LowPart = Seconds;
1046+
}
1047+
}
1048+
10321049
// FIXME: Return the actual statistcs data!
10331050

10341051
*Buffer = pStatBuffer;

0 commit comments

Comments
 (0)