https://git.reactos.org/?p=reactos.git;a=commitdiff;h=4cf5013a5433247934b18…
commit 4cf5013a5433247934b182c59e8a4044d8e95944
Author: Eric Kohl <eric.kohl(a)reactos.org>
AuthorDate: Sat May 18 11:26:02 2019 +0200
Commit: Eric Kohl <eric.kohl(a)reactos.org>
CommitDate: Sat May 18 11:27:00 2019 +0200
[NET] Print raw logon hour ranges in the USER command.
---
base/applications/network/net/cmdUser.c | 85 +++++++++++++++++++++++++++++++--
1 file changed, 82 insertions(+), 3 deletions(-)
diff --git a/base/applications/network/net/cmdUser.c
b/base/applications/network/net/cmdUser.c
index 50cdbf7aee7..5ebef48b127 100644
--- a/base/applications/network/net/cmdUser.c
+++ b/base/applications/network/net/cmdUser.c
@@ -134,14 +134,14 @@ PrintDateTime(DWORD dwSeconds)
&SystemTime,
NULL,
DateBuffer,
- 80);
+ ARRAYSIZE(DateBuffer));
GetTimeFormatW(LOCALE_USER_DEFAULT,
TIME_NOSECONDS,
&SystemTime,
NULL,
TimeBuffer,
- 80);
+ ARRAYSIZE(TimeBuffer));
ConPrintf(StdOut, L"%s %s", DateBuffer, TimeBuffer);
}
@@ -196,6 +196,77 @@ GetCountryFromCountryCode(
}
+static
+BOOL
+BitValue(
+ PBYTE pLogonHours,
+ DWORD dwBitNumber)
+{
+ DWORD dwIndex = dwBitNumber / 8;
+ BYTE Mask = 1 << (dwBitNumber & 7);
+
+ return ((pLogonHours[dwIndex] & Mask) != 0);
+}
+
+
+static
+VOID
+PrintLogonHours(
+ DWORD dwUnitsPerWeek,
+ PBYTE pLogonHours,
+ INT nPaddedLength)
+{
+ DWORD dwUnitsPerDay, dwBitNumber, dwSecondsPerUnit;
+ DWORD dwStartTime, dwEndTime;
+ BOOL bBitValue, bFirst = TRUE;
+
+ if ((dwUnitsPerWeek == 0) ||
+ ((dwUnitsPerWeek %7) != 0))
+ return;
+
+ dwUnitsPerDay = dwUnitsPerWeek / 7;
+
+ if (((dwUnitsPerDay % 24) != 0) ||
+ ((dwUnitsPerDay / 24) > 6))
+ return;
+
+ dwSecondsPerUnit = (24 * 60 * 60) / dwUnitsPerDay;
+
+ for (dwBitNumber = 0; dwBitNumber < dwUnitsPerWeek; dwBitNumber++)
+ {
+ bBitValue = BitValue(pLogonHours, dwBitNumber);
+ if (bBitValue)
+ {
+ dwStartTime = dwSecondsPerUnit * dwBitNumber;
+
+ while (bBitValue != 0 && dwBitNumber < dwUnitsPerWeek)
+ {
+ dwBitNumber++;
+ if (dwBitNumber < dwUnitsPerWeek)
+ bBitValue = BitValue(pLogonHours, dwBitNumber);
+ }
+
+ dwEndTime = dwSecondsPerUnit * dwBitNumber;
+
+ if (!bFirst)
+ PrintPadding(L' ', nPaddedLength);
+
+ if (dwStartTime == 0 && dwEndTime == (60 * 60 * 24 * 7))
+ {
+ PrintMessageString(4302);
+ ConPuts(StdOut, L"\n");
+ }
+ else
+ {
+ ConPrintf(StdOut, L"%lu - %lu\n", dwStartTime, dwEndTime);
+ }
+
+ bFirst = FALSE;
+ }
+ }
+}
+
+
static
NET_API_STATUS
DisplayUser(LPWSTR lpUserName)
@@ -329,8 +400,16 @@ DisplayUser(LPWSTR lpUserName)
PrintPaddedMessageString(4432, nPaddedLength);
if (pUserInfo->usri4_logon_hours == NULL)
+ {
PrintMessageString(4302);
- ConPuts(StdOut, L"\n\n");
+ ConPuts(StdOut, L"\n");
+ }
+ else
+ {
+ PrintLogonHours(pUserInfo->usri4_units_per_week,
+ pUserInfo->usri4_logon_hours,
+ nPaddedLength);
+ }
ConPuts(StdOut, L"\n");
PrintPaddedMessageString(4427, nPaddedLength);