From bb7a6134c42c676d5abb5e14dae8a3d7c2f5568d Mon Sep 17 00:00:00 2001 From: Eric Kohl Date: Sun, 9 Nov 2025 15:21:52 +0100 Subject: [PATCH] [SRVSVC][WKSSVC][NET] Improve server and workstation statistics - Server and Workstation services return proper boot time. - Net formats boot time properly. CORE-19198 --- base/applications/network/net/cmdStatistics.c | 60 ++++++++++--------- base/services/srvsvc/precomp.h | 1 + base/services/srvsvc/rpcserver.c | 18 +++++- base/services/wkssvc/precomp.h | 1 + base/services/wkssvc/rpcserver.c | 19 +++++- 5 files changed, 68 insertions(+), 31 deletions(-) diff --git a/base/applications/network/net/cmdStatistics.c b/base/applications/network/net/cmdStatistics.c index d8e88a46977..f54268dc08b 100644 --- a/base/applications/network/net/cmdStatistics.c +++ b/base/applications/network/net/cmdStatistics.c @@ -18,7 +18,7 @@ DisplayServerStatistics(VOID) LARGE_INTEGER LargeValue; FILETIME FileTime, LocalFileTime; SYSTEMTIME SystemTime; - WORD wHour; + WCHAR DateBuffer[32], TimeBuffer[32]; INT nPaddedLength = 35; NET_API_STATUS Status; @@ -44,21 +44,22 @@ DisplayServerStatistics(VOID) FileTimeToLocalFileTime(&FileTime, &LocalFileTime); FileTimeToSystemTime(&LocalFileTime, &SystemTime); - wHour = SystemTime.wHour; - if (wHour == 0) - { - wHour = 12; - } - else if (wHour > 12) - { - wHour = wHour - 12; - } + GetDateFormatW(LOCALE_USER_DEFAULT, + DATE_SHORTDATE, + &SystemTime, + NULL, + DateBuffer, + ARRAYSIZE(DateBuffer)); + + GetTimeFormatW(LOCALE_USER_DEFAULT, + 0, + &SystemTime, + NULL, + TimeBuffer, + ARRAYSIZE(TimeBuffer)); PrintMessageString(4600); - ConPrintf(StdOut, L" %d/%d/%d %d:%02d %s\n\n\n", - SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear, - wHour, SystemTime.wMinute, - (SystemTime.wHour >= 1 && SystemTime.wHour < 13) ? L"AM" : L"PM"); + ConPrintf(StdOut, L" %s %s\n\n\n", DateBuffer, TimeBuffer); PrintPaddedMessageString(4601, nPaddedLength); ConPrintf(StdOut, L"%lu\n", StatisticsInfo->sts0_sopens); @@ -131,7 +132,7 @@ DisplayWorkstationStatistics(VOID) LARGE_INTEGER LargeValue; FILETIME FileTime, LocalFileTime; SYSTEMTIME SystemTime; - WORD wHour; + WCHAR DateBuffer[32], TimeBuffer[32]; INT nPaddedLength = 47; NET_API_STATUS Status; @@ -142,7 +143,7 @@ DisplayWorkstationStatistics(VOID) goto done; Status = NetStatisticsGet(NULL, - SERVICE_SERVER, + SERVICE_WORKSTATION, 0, 0, (LPBYTE*)&StatisticsInfo); @@ -159,21 +160,22 @@ DisplayWorkstationStatistics(VOID) FileTimeToLocalFileTime(&FileTime, &LocalFileTime); FileTimeToSystemTime(&LocalFileTime, &SystemTime); - wHour = SystemTime.wHour; - if (wHour == 0) - { - wHour = 12; - } - else if (wHour > 12) - { - wHour = wHour - 12; - } + GetDateFormatW(LOCALE_USER_DEFAULT, + DATE_SHORTDATE, + &SystemTime, + NULL, + DateBuffer, + ARRAYSIZE(DateBuffer)); + + GetTimeFormatW(LOCALE_USER_DEFAULT, + 0, + &SystemTime, + NULL, + TimeBuffer, + ARRAYSIZE(TimeBuffer)); PrintMessageString(4600); - ConPrintf(StdOut, L" %d/%d/%d %d:%02d %s\n\n\n", - SystemTime.wMonth, SystemTime.wDay, SystemTime.wYear, - wHour, SystemTime.wMinute, - (SystemTime.wHour >= 1 && SystemTime.wHour < 13) ? L"AM" : L"PM"); + ConPrintf(StdOut, L" %s %s\n\n\n", DateBuffer, TimeBuffer); PrintPaddedMessageString(4630, nPaddedLength); ConPrintf(StdOut, L"%I64u\n", StatisticsInfo->BytesReceived.QuadPart); diff --git a/base/services/srvsvc/precomp.h b/base/services/srvsvc/precomp.h index 6da24c6e0f9..5f1ab2d9526 100644 --- a/base/services/srvsvc/precomp.h +++ b/base/services/srvsvc/precomp.h @@ -10,6 +10,7 @@ #include #include #include +#include #include diff --git a/base/services/srvsvc/rpcserver.c b/base/services/srvsvc/rpcserver.c index 214bf0bfd6e..d5849e6c4d1 100644 --- a/base/services/srvsvc/rpcserver.c +++ b/base/services/srvsvc/rpcserver.c @@ -476,7 +476,9 @@ NetrServerStatisticsGet( DWORD Options, LPSTAT_SERVER_0 *InfoStruct) { - PSTAT_SERVER_0 pStatBuffer; + SYSTEM_TIMEOFDAY_INFORMATION TimeOfDayInfo; + PSTAT_SERVER_0 pStatBuffer = NULL; + NTSTATUS Status; TRACE("NetrServerStatisticsGet(%p %p %lu 0x%lx %p)\n", ServerName, Service, Level, Options, InfoStruct); @@ -493,6 +495,20 @@ NetrServerStatisticsGet( ZeroMemory(pStatBuffer, sizeof(STAT_SERVER_0)); + /* Query the boot time */ + Status = NtQuerySystemInformation(SystemTimeOfDayInformation, + &TimeOfDayInfo, + sizeof(TimeOfDayInfo), + NULL); + if (NT_SUCCESS(Status)) + { + ULONG Seconds = 0; + if (RtlTimeToSecondsSince1970(&TimeOfDayInfo.BootTime, &Seconds)) + { + pStatBuffer->sts0_start = Seconds; + } + } + // FIXME: Return the actual statistcs data! *InfoStruct = pStatBuffer; diff --git a/base/services/wkssvc/precomp.h b/base/services/wkssvc/precomp.h index 71a60f4ea50..380c4c11325 100644 --- a/base/services/wkssvc/precomp.h +++ b/base/services/wkssvc/precomp.h @@ -17,6 +17,7 @@ #include #include //#include +#include #include #include #include diff --git a/base/services/wkssvc/rpcserver.c b/base/services/wkssvc/rpcserver.c index d189c0a5d2f..ea7ac051fb8 100644 --- a/base/services/wkssvc/rpcserver.c +++ b/base/services/wkssvc/rpcserver.c @@ -1012,7 +1012,9 @@ NetrWorkstationStatisticsGet( unsigned long Options, LPSTAT_WORKSTATION_0 *Buffer) { - PSTAT_WORKSTATION_0 pStatBuffer; + SYSTEM_TIMEOFDAY_INFORMATION TimeOfDayInfo; + PSTAT_WORKSTATION_0 pStatBuffer = NULL; + NTSTATUS Status; TRACE("NetrWorkstationStatisticsGet(%p %p %lu 0x%lx %p)\n", ServerName, ServiceName, Level, Options, Buffer); @@ -1029,6 +1031,21 @@ NetrWorkstationStatisticsGet( ZeroMemory(pStatBuffer, sizeof(STAT_WORKSTATION_0)); + /* Query the boot time */ + Status = NtQuerySystemInformation(SystemTimeOfDayInformation, + &TimeOfDayInfo, + sizeof(TimeOfDayInfo), + NULL); + if (NT_SUCCESS(Status)) + { + ULONG Seconds = 0; + if (RtlTimeToSecondsSince1970(&TimeOfDayInfo.BootTime, &Seconds)) + { + pStatBuffer->StatisticsStartTime.u.HighPart = 0; + pStatBuffer->StatisticsStartTime.u.LowPart = Seconds; + } + } + // FIXME: Return the actual statistcs data! *Buffer = pStatBuffer;