#include "net.h"
+#define SECONDS_PER_DAY (60 * 60 * 24)
+#define SECONDS_PER_HOUR (60 * 60)
+#define HOURS_PER_DAY 24
+#define DAYS_PER_WEEK 7
+
typedef struct _COUNTY_TABLE
{
DWORD dwCountryCode;
{785, 5103}, // Arabic
{972, 5104} }; // Hebrew
+//static PWSTR DaysArray[] = {L"So", L"Mo", L"Di", L"Mi", L"Do", L"Fr", L"Sa"};
+static PWSTR DaysArray[] = {L"Sun", L"Mon", L"Tue", L"Wed", L"Thu", L"Fri", L"Sat"};
static
int
&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);
}
+static
+VOID
+PrintLocalTime(DWORD dwSeconds)
+{
+ LARGE_INTEGER Time;
+ FILETIME FileTime;
+ SYSTEMTIME SystemTime;
+ WCHAR TimeBuffer[80];
+
+ RtlSecondsSince1970ToTime(dwSeconds, &Time);
+ FileTime.dwLowDateTime = Time.u.LowPart;
+ FileTime.dwHighDateTime = Time.u.HighPart;
+ FileTimeToSystemTime(&FileTime, &SystemTime);
+
+ GetTimeFormatW(LOCALE_USER_DEFAULT,
+ TIME_NOSECONDS,
+ &SystemTime,
+ NULL,
+ TimeBuffer,
+ ARRAYSIZE(TimeBuffer));
+
+ ConPrintf(StdOut, L"%s", TimeBuffer);
+}
+
+
static
DWORD
GetTimeInSeconds(VOID)
}
+static
+BOOL
+GetBitValue(
+ PBYTE pBitmap,
+ DWORD dwBitNumber)
+{
+ DWORD dwIndex = dwBitNumber / 8;
+ BYTE Mask = 1 << (dwBitNumber & 7);
+
+ return ((pBitmap[dwIndex] & Mask) != 0);
+}
+
+
+static
+VOID
+SetBitValue(
+ PBYTE pBitmap,
+ DWORD dwBitNumber)
+{
+ DWORD dwIndex = dwBitNumber / 8;
+ BYTE Mask = 1 << (dwBitNumber & 7);
+
+ pBitmap[dwIndex] |= Mask;
+}
+
+
+static
+VOID
+PrintLogonHours(
+ DWORD dwUnitsPerWeek,
+ PBYTE pLogonHours,
+ INT nPaddedLength)
+{
+ DWORD dwUnitsPerDay, dwBitNumber, dwSecondsPerUnit;
+ DWORD dwStartTime, dwEndTime, dwStartDay, dwEndDay;
+ BOOL bBitValue, bFirst = TRUE;
+
+ if ((dwUnitsPerWeek == 0) ||
+ ((dwUnitsPerWeek %7) != 0))
+ return;
+
+ dwUnitsPerDay = dwUnitsPerWeek / 7;
+
+ if (((dwUnitsPerDay % 24) != 0) ||
+ ((dwUnitsPerDay / 24) > 6))
+ return;
+
+ dwSecondsPerUnit = (SECONDS_PER_DAY) / dwUnitsPerDay;
+
+ for (dwBitNumber = 0; dwBitNumber < dwUnitsPerWeek; dwBitNumber++)
+ {
+ bBitValue = GetBitValue(pLogonHours, dwBitNumber);
+ if (bBitValue)
+ {
+ dwStartTime = dwSecondsPerUnit * dwBitNumber;
+
+ while (bBitValue != 0 && dwBitNumber < dwUnitsPerWeek)
+ {
+ dwBitNumber++;
+ if (dwBitNumber < dwUnitsPerWeek)
+ bBitValue = GetBitValue(pLogonHours, dwBitNumber);
+ }
+
+ dwEndTime = dwSecondsPerUnit * dwBitNumber;
+
+ if (!bFirst)
+ PrintPadding(L' ', nPaddedLength);
+
+ if (dwStartTime == 0 && dwEndTime == (SECONDS_PER_DAY * 7))
+ {
+ PrintMessageString(4302);
+ ConPuts(StdOut, L"\n");
+ }
+ else
+ {
+ dwStartDay = dwStartTime / SECONDS_PER_DAY;
+ dwEndDay = (dwEndTime / SECONDS_PER_DAY) % 7;
+
+ PrintMessageString(4307 + dwStartDay);
+ ConPuts(StdOut, L" ");
+
+ // FIXME: Check if this is a converion from GMT to local timezone
+ PrintLocalTime((dwStartTime % SECONDS_PER_DAY) + SECONDS_PER_HOUR);
+
+ ConPrintf(StdOut, L" - ");
+ if (dwStartDay != dwEndDay)
+ {
+ PrintMessageString(4307 + dwEndDay);
+ ConPuts(StdOut, L" ");
+ }
+
+ // FIXME: Check if this is a converion from GMT to local timezone
+ PrintLocalTime((dwEndTime % SECONDS_PER_DAY) + SECONDS_PER_HOUR);
+ ConPuts(StdOut, L"\n");
+ }
+
+ bFirst = FALSE;
+ }
+ }
+
+ if (bFirst)
+ {
+ /* No logon hours */
+ PrintMessageString(4434);
+ ConPuts(StdOut, L"\n");
+ }
+}
+
+
static
NET_API_STATUS
DisplayUser(LPWSTR lpUserName)
PrintPaddedMessageString(4419, nPaddedLength);
if (pUserInfo->usri4_flags & UF_ACCOUNTDISABLE)
- ConResPuts(StdOut, IDS_GENERIC_NO);
+ PrintMessageString(4301);
else if (pUserInfo->usri4_flags & UF_LOCKOUT)
PrintMessageString(4440);
else
- ConResPuts(StdOut, IDS_GENERIC_YES);
+ PrintMessageString(4300);
ConPuts(StdOut, L"\n");
PrintPaddedMessageString(4420, nPaddedLength);
if (pUserInfo->usri4_acct_expires == TIMEQ_FOREVER)
- ConResPuts(StdOut, IDS_GENERIC_NEVER);
+ PrintMessageString(4305);
else
PrintDateTime(pUserInfo->usri4_acct_expires);
ConPuts(StdOut, L"\n\n");
PrintPaddedMessageString(4422, nPaddedLength);
if ((pUserInfo->usri4_flags & UF_DONT_EXPIRE_PASSWD) || pUserModals->usrmod0_max_passwd_age == TIMEQ_FOREVER)
- ConResPuts(StdOut, IDS_GENERIC_NEVER);
+ PrintMessageString(4305);
else
PrintDateTime(dwLastSet + pUserModals->usrmod0_max_passwd_age);
ConPuts(StdOut, L"\n");
ConPuts(StdOut, L"\n");
PrintPaddedMessageString(4437, nPaddedLength);
- ConResPuts(StdOut, (pUserInfo->usri4_flags & UF_PASSWD_NOTREQD) ? IDS_GENERIC_NO : IDS_GENERIC_YES);
+ PrintMessageString((pUserInfo->usri4_flags & UF_PASSWD_NOTREQD) ? 4301 : 4300);
ConPuts(StdOut, L"\n");
PrintPaddedMessageString(4438, nPaddedLength);
- ConResPuts(StdOut, (pUserInfo->usri4_flags & UF_PASSWD_CANT_CHANGE) ? IDS_GENERIC_NO : IDS_GENERIC_YES);
+ PrintMessageString((pUserInfo->usri4_flags & UF_PASSWD_CANT_CHANGE) ? 4301 : 4300);
ConPuts(StdOut, L"\n\n");
PrintPaddedMessageString(4424, nPaddedLength);
if (pUserInfo->usri4_workstations == NULL || wcslen(pUserInfo->usri4_workstations) == 0)
- ConResPuts(StdOut, IDS_GENERIC_ALL);
+ PrintMessageString(4302);
else
ConPrintf(StdOut, L"%s", pUserInfo->usri4_workstations);
ConPuts(StdOut, L"\n");
PrintPaddedMessageString(4430, nPaddedLength);
if (pUserInfo->usri4_last_logon == 0)
- ConResPuts(StdOut, IDS_GENERIC_NEVER);
+ PrintMessageString(4305);
else
PrintDateTime(pUserInfo->usri4_last_logon);
ConPuts(StdOut, L"\n\n");
PrintPaddedMessageString(4432, nPaddedLength);
if (pUserInfo->usri4_logon_hours == NULL)
- ConResPuts(StdOut, IDS_GENERIC_ALL);
- ConPuts(StdOut, L"\n\n");
+ {
+ PrintMessageString(4302);
+ ConPuts(StdOut, L"\n");
+ }
+ else
+ {
+ PrintLogonHours(pUserInfo->usri4_units_per_week,
+ pUserInfo->usri4_logon_hours,
+ nPaddedLength);
+ }
ConPuts(StdOut, L"\n");
PrintPaddedMessageString(4427, nPaddedLength);
while (TRUE)
{
- ConResPuts(StdOut, IDS_USER_ENTER_PASSWORD1);
+ PrintMessageString(4358);
ReadFromConsole(szPassword1, PWLEN + 1, FALSE);
ConPuts(StdOut, L"\n");
- ConResPuts(StdOut, IDS_USER_ENTER_PASSWORD2);
+ PrintMessageString(4361);
ReadFromConsole(szPassword2, PWLEN + 1, FALSE);
ConPuts(StdOut, L"\n");
else
{
ConPuts(StdOut, L"\n");
- ConResPuts(StdOut, IDS_USER_NO_PASSWORD_MATCH);
- ConPuts(StdOut, L"\n");
+ PrintMessageString(3728);
*lpPassword = NULL;
}
}
}
+static
+BOOL
+ParseHour(
+ PWSTR pszString,
+ PDWORD pdwHour)
+{
+ PWCHAR pChar;
+ DWORD dwHour = 0;
+
+ if (!iswdigit(pszString[0]))
+ return FALSE;
+
+ pChar = pszString;
+ while (iswdigit(*pChar))
+ {
+ dwHour = dwHour * 10 + *pChar - L'0';
+ pChar++;
+ }
+
+ if (dwHour > 24)
+ return FALSE;
+
+ if (dwHour == 24)
+ dwHour = 0;
+
+ if ((*pChar != UNICODE_NULL) &&
+ (dwHour >= 1) &&
+ (dwHour <= 12))
+ {
+ if ((_wcsicmp(pChar, L"am") == 0) ||
+ (_wcsicmp(pChar, L"a.m.") == 0))
+ {
+ if (dwHour == 12)
+ dwHour = 0;
+ }
+ else if ((_wcsicmp(pChar, L"pm") == 0) ||
+ (_wcsicmp(pChar, L"p.m.") == 0))
+ {
+ if (dwHour != 12)
+ dwHour += 12;
+ }
+ else
+ {
+ return FALSE;
+ }
+ }
+
+ *pdwHour = dwHour;
+
+ return TRUE;
+}
+
+
+static
+BOOL
+ParseDay(
+ PWSTR pszString,
+ PDWORD pdwDay)
+{
+ DWORD i;
+
+ for (i = 0; i < ARRAYSIZE(DaysArray); i++)
+ {
+ if (_wcsicmp(pszString, DaysArray[i]) == 0)
+ {
+ *pdwDay = i;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+
+static
+DWORD
+ParseLogonHours(
+ PWSTR pszParams,
+ PBYTE *ppLogonBitmap,
+ PDWORD pdwUnitsPerWeek)
+{
+ PBYTE pLogonBitmap = NULL;
+ DWORD dwError = ERROR_SUCCESS;
+ WCHAR szBuffer[32];
+ PWSTR ptr1, ptr2;
+ WCHAR prevSep, nextSep;
+ DWORD dwStartHour, dwEndHour, dwStartDay, dwEndDay, i, j;
+ BYTE DayBitmap;
+ BYTE HourBitmap[6];
+
+ pLogonBitmap = HeapAlloc(GetProcessHeap(),
+ HEAP_ZERO_MEMORY,
+ UNITS_PER_WEEK / 8);
+ if (pLogonBitmap == NULL)
+ return ERROR_OUTOFMEMORY;
+
+ if (*pszParams == UNICODE_NULL)
+ {
+ goto done;
+ }
+
+ if (wcsicmp(pszParams, L"all") == 0)
+ {
+ FillMemory(pLogonBitmap, UNITS_PER_WEEK / 8, 0xFF);
+ goto done;
+ }
+
+ ZeroMemory(&DayBitmap, sizeof(DayBitmap));
+ ZeroMemory(HourBitmap, sizeof(HourBitmap));
+
+ ZeroMemory(szBuffer, sizeof(szBuffer));
+ ptr1 = pszParams;
+ ptr2 = szBuffer;
+ prevSep = UNICODE_NULL;
+ nextSep = UNICODE_NULL;
+ for (;;)
+ {
+ if (*ptr1 != L'-' && *ptr1 != L',' && *ptr1 != L';' && *ptr1 != UNICODE_NULL)
+ {
+ *ptr2 = *ptr1;
+ ptr2++;
+ }
+ else
+ {
+ prevSep = nextSep;
+ nextSep = *ptr1;
+
+// printf("Token: '%S'\n", szBuffer);
+ if (*ptr1 != UNICODE_NULL)
+ printf("Separator: '%C'\n", *ptr1);
+
+ if (prevSep != L'-')
+ {
+ // Set first value
+ if (iswdigit(szBuffer[0]))
+ {
+ // parse hour
+ if (!ParseHour(szBuffer, &dwStartHour))
+ {
+ dwError = 3769;
+ break;
+ }
+
+ // FIXME: Check if this is a converion from local timezone to GMT
+ if (dwStartHour > 0)
+ dwStartHour--;
+ else
+ dwStartHour = UNITS_PER_WEEK - 1;
+
+ SetBitValue(HourBitmap, dwStartHour);
+ }
+ else
+ {
+ // parse day
+ if (!ParseDay(szBuffer, &dwStartDay))
+ {
+ dwError = 3768;
+ break;
+ }
+
+ SetBitValue(&DayBitmap, dwStartDay);
+ }
+ }
+ else
+ {
+ // Set second value
+ if (iswdigit(szBuffer[0]))
+ {
+ // parse hour
+ if (!ParseHour(szBuffer, &dwEndHour))
+ {
+ dwError = 3769;
+ break;
+ }
+
+ if (dwEndHour < dwStartHour)
+ dwEndHour += HOURS_PER_DAY;
+ else if (dwEndHour == dwStartHour)
+ dwEndHour = dwStartHour + HOURS_PER_DAY;
+
+ // FIXME: Check if this is a converion from local timezone to GMT
+ if (dwEndHour > 0)
+ dwEndHour--;
+ else
+ dwEndHour = UNITS_PER_WEEK - 1;
+
+ for (i = dwStartHour; i < dwEndHour; i++)
+ SetBitValue(HourBitmap, i);
+ }
+ else
+ {
+ // parse day
+ if (!ParseDay(szBuffer, &dwEndDay))
+ {
+ dwError = 3768;
+ break;
+ }
+
+ if (dwEndDay <= dwStartDay)
+ dwEndDay += DAYS_PER_WEEK;
+
+ for (i = dwStartDay; i <= dwEndDay; i++)
+ SetBitValue(&DayBitmap, i % DAYS_PER_WEEK);
+ }
+ }
+
+ if (*ptr1 == L';' || *ptr1 == UNICODE_NULL)
+ {
+ // Process the data
+// printf("DayBitmap: %02x HourBitmap: %02x%02x%02x%02x%02x%02x\n",
+// DayBitmap, HourBitmap[5], HourBitmap[4], HourBitmap[3], HourBitmap[2], HourBitmap[1], HourBitmap[0]);
+
+ for (i = 0; i < DAYS_PER_WEEK; i++)
+ {
+ if (GetBitValue(&DayBitmap, i))
+ {
+ for (j = 0; j < 48; j++)
+ {
+ if (GetBitValue(HourBitmap, j))
+ SetBitValue(pLogonBitmap, ((i * HOURS_PER_DAY) + j) % UNITS_PER_WEEK);
+ }
+ }
+ }
+
+ // Reset the Bitmaps
+ ZeroMemory(&DayBitmap, sizeof(DayBitmap));
+ ZeroMemory(HourBitmap, sizeof(HourBitmap));
+ }
+
+ if (*ptr1 == UNICODE_NULL)
+ {
+// printf("Done\n");
+ break;
+ }
+
+ ZeroMemory(szBuffer, sizeof(szBuffer));
+ ptr2 = szBuffer;
+ }
+
+ ptr1++;
+ }
+
+#if 0
+ printf("LogonBitmap:\n");
+ for (i = 0; i < DAYS_PER_WEEK; i++)
+ {
+ j = i * 3;
+ printf("%lu: %02x%02x%02x\n", i, pLogonHours[j + 2], pLogonHours[j + 1], pLogonHours[j + 0]);
+ }
+ printf("\n");
+#endif
+
+done:
+ if (dwError == ERROR_SUCCESS)
+ {
+ *ppLogonBitmap = pLogonBitmap;
+ *pdwUnitsPerWeek = UNITS_PER_WEEK;
+ }
+ else
+ {
+ if (pLogonBitmap != NULL)
+ HeapFree(GetProcessHeap(), 0, pLogonBitmap);
+ *ppLogonBitmap = NULL;
+ *pdwUnitsPerWeek = 0;
+ }
+
+ return dwError;
+}
+
+
INT
cmdUser(
INT argc,
LPWSTR endptr;
DWORD value;
BOOL bPasswordAllocated = FALSE;
+ PBYTE pLogonHours = NULL;
+ DWORD dwUnitsPerWeek;
NET_API_STATUS Status;
i = 2;
}
else if (_wcsicmp(argv[j], L"/domain") == 0)
{
- ConResPrintf(StdErr, IDS_ERROR_OPTION_NOT_SUPPORTED, L"/DOMAIN");
+ ConPuts(StdErr, L"The /DOMAIN option is not supported yet.\n");
#if 0
bDomain = TRUE;
#endif
ConPrintf(StdOut, L"Status: %lu\n", Status);
return 0;
}
- else if (lpUserName != NULL && lpPassword == NULL)
+ else if (lpUserName != NULL && lpPassword == NULL && argc == 3)
{
Status = DisplayUser(lpUserName);
ConPrintf(StdOut, L"Status: %lu\n", Status);
}
else
{
- ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/ACTIVE");
+ PrintMessageStringV(3952, L"/ACTIVE");
result = 1;
goto done;
}
value = wcstoul(p, &endptr, 10);
if (*endptr != 0)
{
- ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/COUNTRYCODE");
+ PrintMessageStringV(3952, L"/COUNTRYCODE");
result = 1;
goto done;
}
}
else if (!ParseDate(p, &pUserInfo->usri4_acct_expires))
{
- ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/EXPIRES");
+ PrintMessageStringV(3952, L"/EXPIRES");
result = 1;
goto done;
}
}
else
{
- ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/PASSWORDCHG");
+ PrintMessageStringV(3952, L"/PASSWORDCHG");
result = 1;
goto done;
}
}
else
{
- ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/PASSWORDREQ");
+ PrintMessageStringV(3952, L"/PASSWORDREQ");
result = 1;
goto done;
}
}
else if (_wcsnicmp(argv[j], L"/times:", 7) == 0)
{
- /* FIXME */
- ConResPrintf(StdErr, IDS_ERROR_OPTION_NOT_SUPPORTED, L"/TIMES");
+ Status = ParseLogonHours(&argv[j][7],
+ &pLogonHours,
+ &dwUnitsPerWeek);
+ if (Status == ERROR_SUCCESS)
+ {
+ pUserInfo->usri4_logon_hours = pLogonHours;
+ pUserInfo->usri4_units_per_week = dwUnitsPerWeek;
+ }
+ else
+ {
+ PrintMessageString(Status);
+ goto done;
+ }
}
else if (_wcsnicmp(argv[j], L"/usercomment:", 13) == 0)
{
lpPassword != NULL &&
bRandomPassword == TRUE)
{
- ConPrintf(StdOut, L"The password for %s is: %s\n", lpUserName, lpPassword);
+ PrintMessageStringV(3968, lpUserName, lpPassword);
}
done:
+ if (pLogonHours != NULL)
+ HeapFree(GetProcessHeap(), 0, pLogonHours);
+
if (pWorkstations != NULL)
HeapFree(GetProcessHeap(), 0, pWorkstations);
if (result != 0)
{
- ConResPuts(StdOut, IDS_GENERIC_SYNTAX);
+ PrintMessageString(4381);
+ ConPuts(StdOut, L"\n");
PrintNetMessage(MSG_USER_SYNTAX);
}