ReactOS 0.4.16-dev-303-g11d5cb8
cmdUser.c File Reference
#include "net.h"
Include dependency graph for cmdUser.c:

Go to the source code of this file.

Classes

struct  _COUNTY_TABLE
 

Macros

#define SECONDS_PER_DAY   (60 * 60 * 24)
 
#define SECONDS_PER_HOUR   (60 * 60)
 
#define HOURS_PER_DAY   24
 
#define DAYS_PER_WEEK   7
 

Typedefs

typedef struct _COUNTY_TABLE COUNTRY_TABLE
 
typedef struct _COUNTY_TABLEPCOUNTRY_TABLE
 

Functions

static int CompareInfo (const void *a, const void *b)
 
static NET_API_STATUS EnumerateUsers (VOID)
 
static VOID PrintDateTime (DWORD dwSeconds)
 
static VOID PrintLocalTime (DWORD dwSeconds)
 
static DWORD GetTimeInSeconds (VOID)
 
static BOOL GetCountryFromCountryCode (_In_ DWORD dwCountryCode, _In_ DWORD dwCountryLength, _Out_ PWSTR szCountryBuffer)
 
static BOOL GetBitValue (PBYTE pBitmap, DWORD dwBitNumber)
 
static VOID SetBitValue (PBYTE pBitmap, DWORD dwBitNumber)
 
static VOID PrintLogonHours (DWORD dwUnitsPerWeek, PBYTE pLogonHours, INT nPaddedLength)
 
static NET_API_STATUS DisplayUser (LPWSTR lpUserName)
 
static VOID ReadPassword (LPWSTR *lpPassword, LPBOOL lpAllocated)
 
static VOID GenerateRandomPassword (LPWSTR *lpPassword, LPBOOL lpAllocated)
 
static NET_API_STATUS BuildWorkstationsList (_Out_ PWSTR *pWorkstationsList, _In_ PWSTR pRaw)
 
static BOOL ReadNumber (PWSTR *s, PWORD pwValue)
 
static BOOL ReadSeparator (PWSTR *s)
 
static BOOL ParseDate (PWSTR s, PULONG pSeconds)
 
static BOOL ParseHour (PWSTR pszString, PWSTR *AmPmArray, PLONG plHour)
 
static BOOL ParseDay (PWSTR pszString, PWSTR *ShortDays, PWSTR *LongDays, PDWORD pdwDay)
 
static DWORD LocalToGmtHour (LONG lLocalHour, LONG lBias)
 
static DWORD ParseLogonHours (PWSTR pszParams, PBYTE *ppLogonBitmap, PDWORD pdwUnitsPerWeek)
 
INT cmdUser (INT argc, WCHAR **argv)
 

Variables

static WCHAR szPasswordChars [] = L"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%_-+:"
 
static COUNTRY_TABLE CountryTable []
 

Macro Definition Documentation

◆ DAYS_PER_WEEK

#define DAYS_PER_WEEK   7

Definition at line 16 of file cmdUser.c.

◆ HOURS_PER_DAY

#define HOURS_PER_DAY   24

Definition at line 15 of file cmdUser.c.

◆ SECONDS_PER_DAY

#define SECONDS_PER_DAY   (60 * 60 * 24)

Definition at line 13 of file cmdUser.c.

◆ SECONDS_PER_HOUR

#define SECONDS_PER_HOUR   (60 * 60)

Definition at line 14 of file cmdUser.c.

Typedef Documentation

◆ COUNTRY_TABLE

◆ PCOUNTRY_TABLE

Function Documentation

◆ BuildWorkstationsList()

static NET_API_STATUS BuildWorkstationsList ( _Out_ PWSTR pWorkstationsList,
_In_ PWSTR  pRaw 
)
static

Definition at line 611 of file cmdUser.c.

614{
615 BOOL isLastSep, isSep;
616 INT i, j;
617 WCHAR c;
618 INT nLength = 0;
619 INT nArgs = 0;
620 INT nRawLength;
621 PWSTR pList;
622
623 /* Check for invalid characters in the raw string */
624 if (wcspbrk(pRaw, L"/[]=?\\+:.") != NULL)
625 return 3952;
626
627 /* Count the number of workstations in the list and
628 * the required buffer size */
629 isLastSep = FALSE;
630 isSep = FALSE;
631 nRawLength = wcslen(pRaw);
632 for (i = 0; i < nRawLength; i++)
633 {
634 c = pRaw[i];
635 if (c == L',' || c == L';')
636 isSep = TRUE;
637
638 if (isSep == TRUE)
639 {
640 if ((isLastSep == FALSE) && (i != 0) && (i != nRawLength - 1))
641 nLength++;
642 }
643 else
644 {
645 nLength++;
646
647 if (isLastSep == TRUE || (isLastSep == FALSE && i == 0))
648 nArgs++;
649 }
650
651 isLastSep = isSep;
652 isSep = FALSE;
653 }
654
655 nLength++;
656
657 /* Leave, if there are no workstations in the list */
658 if (nArgs == 0)
659 {
660 pWorkstationsList = NULL;
661 return NERR_Success;
662 }
663
664 /* Fail if there are more than eight workstations in the list */
665 if (nArgs > 8)
666 return 3951;
667
668 /* Allocate the buffer for the clean workstation list */
670 if (pList == NULL)
672
673 /* Build the clean workstation list */
674 isLastSep = FALSE;
675 isSep = FALSE;
676 nRawLength = wcslen(pRaw);
677 for (i = 0, j = 0; i < nRawLength; i++)
678 {
679 c = pRaw[i];
680 if (c == L',' || c == L';')
681 isSep = TRUE;
682
683 if (isSep == TRUE)
684 {
685 if ((isLastSep == FALSE) && (i != 0) && (i != nRawLength - 1))
686 {
687 pList[j] = L',';
688 j++;
689 }
690 }
691 else
692 {
693 pList[j] = c;
694 j++;
695
696 if (isLastSep == TRUE || (isLastSep == FALSE && i == 0))
697 nArgs++;
698 }
699
700 isLastSep = isSep;
701 isSep = FALSE;
702 }
703
704 *pWorkstationsList = pList;
705
706 return NERR_Success;
707}
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
unsigned int BOOL
Definition: ntddk_ex.h:94
FxChildList * pList
const GLubyte * c
Definition: glext.h:8905
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define c
Definition: ke_i.h:80
#define NERR_Success
Definition: lmerr.h:5
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcspbrk(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_Control)
uint16_t * PWSTR
Definition: typedefs.h:56
int32_t INT
Definition: typedefs.h:58
_In_ DWORD nLength
Definition: wincon.h:473
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by cmdUser().

◆ cmdUser()

INT cmdUser ( INT  argc,
WCHAR **  argv 
)

Definition at line 1148 of file cmdUser.c.

1151{
1152 INT i, j;
1153 INT result = 0;
1154 BOOL bAdd = FALSE;
1155 BOOL bDelete = FALSE;
1156#if 0
1157 BOOL bDomain = FALSE;
1158#endif
1159 BOOL bRandomPassword = FALSE;
1160 LPWSTR lpUserName = NULL;
1161 LPWSTR lpPassword = NULL;
1162 PUSER_INFO_4 pUserInfo = NULL;
1163 USER_INFO_4 UserInfo;
1164 LPWSTR pWorkstations = NULL;
1165 LPWSTR p;
1166 LPWSTR endptr;
1167 DWORD value;
1168 BOOL bPasswordAllocated = FALSE;
1169 PBYTE pLogonHours = NULL;
1170 DWORD dwUnitsPerWeek;
1172
1173 i = 2;
1174 if ((i < argc) && (argv[i][0] != L'/'))
1175 {
1176 lpUserName = argv[i];
1177// ConPrintf(StdOut, L"User: %s\n", lpUserName);
1178 i++;
1179 }
1180
1181 if ((i < argc) && (argv[i][0] != L'/'))
1182 {
1183 lpPassword = argv[i];
1184// ConPrintf(StdOut, L"Password: %s\n", lpPassword);
1185 i++;
1186 }
1187
1188 for (j = i; j < argc; j++)
1189 {
1190 if (_wcsicmp(argv[j], L"/help") == 0)
1191 {
1192 PrintNetMessage(MSG_USER_HELP);
1193 return 0;
1194 }
1195 else if (_wcsicmp(argv[j], L"/add") == 0)
1196 {
1197 bAdd = TRUE;
1198 }
1199 else if (_wcsicmp(argv[j], L"/delete") == 0)
1200 {
1201 bDelete = TRUE;
1202 }
1203 else if (_wcsicmp(argv[j], L"/domain") == 0)
1204 {
1205 ConPuts(StdErr, L"The /DOMAIN option is not supported yet.\n");
1206#if 0
1207 bDomain = TRUE;
1208#endif
1209 }
1210 else if (_wcsicmp(argv[j], L"/random") == 0)
1211 {
1212 bRandomPassword = TRUE;
1213 GenerateRandomPassword(&lpPassword,
1214 &bPasswordAllocated);
1215 }
1216 }
1217
1218 if (lpUserName == NULL && lpPassword == NULL)
1219 {
1222 return 0;
1223 }
1224 else if (lpUserName != NULL && lpPassword == NULL && argc == 3)
1225 {
1226 Status = DisplayUser(lpUserName);
1228 return 0;
1229 }
1230
1231 if (bAdd && bDelete)
1232 {
1233 result = 1;
1234 goto done;
1235 }
1236
1237 /* Interactive password input */
1238 if (lpPassword != NULL && wcscmp(lpPassword, L"*") == 0)
1239 {
1240 ReadPassword(&lpPassword,
1241 &bPasswordAllocated);
1242 }
1243
1244 if (!bAdd && !bDelete)
1245 {
1246 /* Modify the user */
1248 lpUserName,
1249 4,
1250 (LPBYTE*)&pUserInfo);
1251 if (Status != NERR_Success)
1252 {
1254 result = 1;
1255 goto done;
1256 }
1257 }
1258 else if (bAdd)
1259 {
1260 /* Add the user */
1261 ZeroMemory(&UserInfo, sizeof(USER_INFO_4));
1262
1263 UserInfo.usri4_name = lpUserName;
1264 UserInfo.usri4_password = lpPassword;
1268
1269 pUserInfo = &UserInfo;
1270 }
1271
1272 for (j = i; j < argc; j++)
1273 {
1274 if (_wcsnicmp(argv[j], L"/active:", 8) == 0)
1275 {
1276 p = &argv[i][8];
1277 if (_wcsicmp(p, L"yes") == 0)
1278 {
1279 pUserInfo->usri4_flags &= ~UF_ACCOUNTDISABLE;
1280 }
1281 else if (_wcsicmp(p, L"no") == 0)
1282 {
1283 pUserInfo->usri4_flags |= UF_ACCOUNTDISABLE;
1284 }
1285 else
1286 {
1287 PrintMessageStringV(3952, L"/ACTIVE");
1288 result = 1;
1289 goto done;
1290 }
1291 }
1292 else if (_wcsnicmp(argv[j], L"/comment:", 9) == 0)
1293 {
1294 pUserInfo->usri4_comment = &argv[j][9];
1295 }
1296 else if (_wcsnicmp(argv[j], L"/countrycode:", 13) == 0)
1297 {
1298 p = &argv[i][13];
1299 value = wcstoul(p, &endptr, 10);
1300 if (*endptr != 0)
1301 {
1302 PrintMessageStringV(3952, L"/COUNTRYCODE");
1303 result = 1;
1304 goto done;
1305 }
1306
1307 /* Verify the country code */
1309 pUserInfo->usri4_country_code = value;
1310 }
1311 else if (_wcsnicmp(argv[j], L"/expires:", 9) == 0)
1312 {
1313 p = &argv[i][9];
1314 if (_wcsicmp(p, L"never") == 0)
1315 {
1316 pUserInfo->usri4_acct_expires = TIMEQ_FOREVER;
1317 }
1318 else if (!ParseDate(p, &pUserInfo->usri4_acct_expires))
1319 {
1320 PrintMessageStringV(3952, L"/EXPIRES");
1321 result = 1;
1322 goto done;
1323 }
1324 }
1325 else if (_wcsnicmp(argv[j], L"/fullname:", 10) == 0)
1326 {
1327 pUserInfo->usri4_full_name = &argv[j][10];
1328 }
1329 else if (_wcsnicmp(argv[j], L"/homedir:", 9) == 0)
1330 {
1331 pUserInfo->usri4_home_dir = &argv[j][9];
1332 }
1333 else if (_wcsnicmp(argv[j], L"/passwordchg:", 13) == 0)
1334 {
1335 p = &argv[i][13];
1336 if (_wcsicmp(p, L"yes") == 0)
1337 {
1338 pUserInfo->usri4_flags &= ~UF_PASSWD_CANT_CHANGE;
1339 }
1340 else if (_wcsicmp(p, L"no") == 0)
1341 {
1342 pUserInfo->usri4_flags |= UF_PASSWD_CANT_CHANGE;
1343 }
1344 else
1345 {
1346 PrintMessageStringV(3952, L"/PASSWORDCHG");
1347 result = 1;
1348 goto done;
1349 }
1350 }
1351 else if (_wcsnicmp(argv[j], L"/passwordreq:", 13) == 0)
1352 {
1353 p = &argv[i][13];
1354 if (_wcsicmp(p, L"yes") == 0)
1355 {
1356 pUserInfo->usri4_flags &= ~UF_PASSWD_NOTREQD;
1357 }
1358 else if (_wcsicmp(p, L"no") == 0)
1359 {
1360 pUserInfo->usri4_flags |= UF_PASSWD_NOTREQD;
1361 }
1362 else
1363 {
1364 PrintMessageStringV(3952, L"/PASSWORDREQ");
1365 result = 1;
1366 goto done;
1367 }
1368 }
1369 else if (_wcsnicmp(argv[j], L"/profilepath:", 13) == 0)
1370 {
1371 pUserInfo->usri4_profile = &argv[j][13];
1372 }
1373 else if (_wcsnicmp(argv[j], L"/scriptpath:", 12) == 0)
1374 {
1375 pUserInfo->usri4_script_path = &argv[j][12];
1376 }
1377 else if (_wcsnicmp(argv[j], L"/times:", 7) == 0)
1378 {
1380 &pLogonHours,
1381 &dwUnitsPerWeek);
1382 if (Status == ERROR_SUCCESS)
1383 {
1384 pUserInfo->usri4_logon_hours = pLogonHours;
1385 pUserInfo->usri4_units_per_week = dwUnitsPerWeek;
1386 }
1387 else
1388 {
1390 goto done;
1391 }
1392 }
1393 else if (_wcsnicmp(argv[j], L"/usercomment:", 13) == 0)
1394 {
1395 pUserInfo->usri4_usr_comment = &argv[j][13];
1396 }
1397 else if (_wcsnicmp(argv[j], L"/workstations:", 14) == 0)
1398 {
1399 p = &argv[i][14];
1400 if (wcscmp(p, L"*") == 0 || wcscmp(p, L"") == 0)
1401 {
1402 pUserInfo->usri4_workstations = NULL;
1403 }
1404 else
1405 {
1406 Status = BuildWorkstationsList(&pWorkstations, p);
1407 if (Status == NERR_Success)
1408 {
1409 pUserInfo->usri4_workstations = pWorkstations;
1410 }
1411 else
1412 {
1414 result = 1;
1415 goto done;
1416 }
1417 }
1418 }
1419 }
1420
1421 if (!bAdd && !bDelete)
1422 {
1423 /* Modify the user */
1425 lpUserName,
1426 4,
1427 (LPBYTE)pUserInfo,
1428 NULL);
1429 }
1430 else if (bAdd)
1431 {
1432 /* Add the user */
1434 4,
1435 (LPBYTE)pUserInfo,
1436 NULL);
1437 }
1438 else if (bDelete)
1439 {
1440 /* Delete the user */
1442 lpUserName);
1443 }
1444
1446
1447 if (Status == NERR_Success &&
1448 lpPassword != NULL &&
1449 bRandomPassword == TRUE)
1450 {
1451 PrintMessageStringV(3968, lpUserName, lpPassword);
1452 }
1453
1454done:
1455 if (pLogonHours != NULL)
1456 HeapFree(GetProcessHeap(), 0, pLogonHours);
1457
1458 if (pWorkstations != NULL)
1459 HeapFree(GetProcessHeap(), 0, pWorkstations);
1460
1461 if ((bPasswordAllocated == TRUE) && (lpPassword != NULL))
1462 HeapFree(GetProcessHeap(), 0, lpPassword);
1463
1464 if (!bAdd && !bDelete && pUserInfo != NULL)
1465 NetApiBufferFree(pUserInfo);
1466
1467 if (result != 0)
1468 {
1469 PrintMessageString(4381);
1470 ConPuts(StdOut, L"\n");
1471 PrintNetMessage(MSG_USER_SYNTAX);
1472 }
1473
1474 return result;
1475}
static int argc
Definition: ServiceArgs.c:12
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define StdOut
Definition: fc.c:14
#define StdErr
Definition: fc.c:15
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:239
DWORD TranslateAppMessage(DWORD dwMessage)
Definition: main.c:79
VOID PrintMessageStringV(DWORD dwMessage,...)
Definition: main.c:93
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:120
static BOOL ParseDate(PWSTR s, PULONG pSeconds)
Definition: cmdUser.c:746
static VOID GenerateRandomPassword(LPWSTR *lpPassword, LPBOOL lpAllocated)
Definition: cmdUser.c:582
static NET_API_STATUS BuildWorkstationsList(_Out_ PWSTR *pWorkstationsList, _In_ PWSTR pRaw)
Definition: cmdUser.c:611
static BOOL GetCountryFromCountryCode(_In_ DWORD dwCountryCode, _In_ DWORD dwCountryLength, _Out_ PWSTR szCountryBuffer)
Definition: cmdUser.c:199
static VOID ReadPassword(LPWSTR *lpPassword, LPBOOL lpAllocated)
Definition: cmdUser.c:536
static DWORD ParseLogonHours(PWSTR pszParams, PBYTE *ppLogonBitmap, PDWORD pdwUnitsPerWeek)
Definition: cmdUser.c:932
static NET_API_STATUS EnumerateUsers(VOID)
Definition: cmdUser.c:65
static NET_API_STATUS DisplayUser(LPWSTR lpUserName)
Definition: cmdUser.c:344
#define ERROR_SUCCESS
Definition: deptool.c:10
#define HeapFree(x, y, z)
Definition: compat.h:735
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
NET_API_STATUS WINAPI NetUserAdd(LPCWSTR servername, DWORD level, LPBYTE bufptr, LPDWORD parm_err)
Definition: user.c:2273
NET_API_STATUS WINAPI NetUserGetInfo(LPCWSTR servername, LPCWSTR username, DWORD level, LPBYTE *bufptr)
Definition: user.c:3147
NET_API_STATUS WINAPI NetUserSetInfo(LPCWSTR servername, LPCWSTR username, DWORD level, LPBYTE buf, LPDWORD parm_err)
Definition: user.c:3975
NET_API_STATUS WINAPI NetUserDel(LPCWSTR servername, LPCWSTR username)
Definition: user.c:2543
unsigned long DWORD
Definition: ntddk_ex.h:95
Status
Definition: gdiplustypes.h:25
GLfloat GLfloat p
Definition: glext.h:8902
GLuint64EXT * result
Definition: glext.h:11304
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define UF_ACCOUNTDISABLE
Definition: lmaccess.h:24
#define UF_PASSWD_CANT_CHANGE
Definition: lmaccess.h:28
#define UF_PASSWD_NOTREQD
Definition: lmaccess.h:27
#define UF_SCRIPT
Definition: lmaccess.h:23
#define UF_NORMAL_ACCOUNT
Definition: lmaccess.h:30
#define TIMEQ_FOREVER
Definition: lmaccess.h:110
#define argv
Definition: mplay32.c:18
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
BYTE * PBYTE
Definition: pedump.c:66
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
LPWSTR usri4_workstations
Definition: lmaccess.h:282
DWORD usri4_flags
Definition: lmaccess.h:276
LPWSTR usri4_comment
Definition: lmaccess.h:275
DWORD usri4_primary_group_id
Definition: lmaccess.h:295
DWORD usri4_units_per_week
Definition: lmaccess.h:287
DWORD usri4_acct_expires
Definition: lmaccess.h:285
LPWSTR usri4_profile
Definition: lmaccess.h:296
LPWSTR usri4_usr_comment
Definition: lmaccess.h:280
LPWSTR usri4_name
Definition: lmaccess.h:270
LPWSTR usri4_password
Definition: lmaccess.h:271
DWORD usri4_country_code
Definition: lmaccess.h:292
LPWSTR usri4_home_dir
Definition: lmaccess.h:274
PBYTE usri4_logon_hours
Definition: lmaccess.h:288
LPWSTR usri4_full_name
Definition: lmaccess.h:279
LPWSTR usri4_script_path
Definition: lmaccess.h:277
unsigned char * LPBYTE
Definition: typedefs.h:53
Definition: pdh_main.c:94
#define ZeroMemory
Definition: winbase.h:1737
#define DOMAIN_GROUP_RID_USERS
Definition: setypes.h:640
WCHAR * LPWSTR
Definition: xmlstorage.h:184

◆ CompareInfo()

static int CompareInfo ( const void a,
const void b 
)
static

Definition at line 56 of file cmdUser.c.

57{
58 return _wcsicmp(((PUSER_INFO_0)a)->usri0_name,
59 ((PUSER_INFO_0)b)->usri0_name);
60}
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by EnumerateUsers().

◆ DisplayUser()

static NET_API_STATUS DisplayUser ( LPWSTR  lpUserName)
static

Definition at line 344 of file cmdUser.c.

345{
346 PUSER_MODALS_INFO_0 pUserModals = NULL;
347 PUSER_INFO_4 pUserInfo = NULL;
348 PLOCALGROUP_USERS_INFO_0 pLocalGroupInfo = NULL;
349 PGROUP_USERS_INFO_0 pGroupInfo = NULL;
350 DWORD dwLocalGroupRead, dwLocalGroupTotal;
351 DWORD dwGroupRead, dwGroupTotal;
352 DWORD dwLastSet;
353 DWORD i;
354 WCHAR szCountry[40];
355 INT nPaddedLength = 36;
357
358 /* Modify the user */
360 lpUserName,
361 4,
362 (LPBYTE*)&pUserInfo);
363 if (Status != NERR_Success)
364 return Status;
365
367 0,
368 (LPBYTE*)&pUserModals);
369 if (Status != NERR_Success)
370 goto done;
371
373 lpUserName,
374 0,
375 0,
376 (LPBYTE*)&pLocalGroupInfo,
378 &dwLocalGroupRead,
379 &dwLocalGroupTotal);
380 if (Status != NERR_Success)
381 goto done;
382
384 lpUserName,
385 0,
386 (LPBYTE*)&pGroupInfo,
388 &dwGroupRead,
389 &dwGroupTotal);
390 if (Status != NERR_Success)
391 goto done;
392
393 PrintPaddedMessageString(4411, nPaddedLength);
394 ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_name);
395
396 PrintPaddedMessageString(4412, nPaddedLength);
397 ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_full_name);
398
399 PrintPaddedMessageString(4413, nPaddedLength);
400 ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_comment);
401
402 PrintPaddedMessageString(4414, nPaddedLength);
403 ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_usr_comment);
404
405 PrintPaddedMessageString(4416, nPaddedLength);
407 ARRAYSIZE(szCountry), szCountry);
408 ConPrintf(StdOut, L"%03ld (%s)\n", pUserInfo->usri4_country_code, szCountry);
409
410 PrintPaddedMessageString(4419, nPaddedLength);
411 if (pUserInfo->usri4_flags & UF_ACCOUNTDISABLE)
412 PrintMessageString(4301);
413 else if (pUserInfo->usri4_flags & UF_LOCKOUT)
414 PrintMessageString(4440);
415 else
416 PrintMessageString(4300);
417 ConPuts(StdOut, L"\n");
418
419 PrintPaddedMessageString(4420, nPaddedLength);
420 if (pUserInfo->usri4_acct_expires == TIMEQ_FOREVER)
421 PrintMessageString(4305);
422 else
424 ConPuts(StdOut, L"\n\n");
425
426 PrintPaddedMessageString(4421, nPaddedLength);
427 dwLastSet = GetTimeInSeconds() - pUserInfo->usri4_password_age;
428 PrintDateTime(dwLastSet);
429 ConPuts(StdOut, L"\n");
430
431 PrintPaddedMessageString(4422, nPaddedLength);
432 if ((pUserInfo->usri4_flags & UF_DONT_EXPIRE_PASSWD) || pUserModals->usrmod0_max_passwd_age == TIMEQ_FOREVER)
433 PrintMessageString(4305);
434 else
435 PrintDateTime(dwLastSet + pUserModals->usrmod0_max_passwd_age);
436 ConPuts(StdOut, L"\n");
437
438 PrintPaddedMessageString(4423, nPaddedLength);
439 PrintDateTime(dwLastSet + pUserModals->usrmod0_min_passwd_age);
440 ConPuts(StdOut, L"\n");
441
442 PrintPaddedMessageString(4437, nPaddedLength);
443 PrintMessageString((pUserInfo->usri4_flags & UF_PASSWD_NOTREQD) ? 4301 : 4300);
444 ConPuts(StdOut, L"\n");
445
446 PrintPaddedMessageString(4438, nPaddedLength);
447 PrintMessageString((pUserInfo->usri4_flags & UF_PASSWD_CANT_CHANGE) ? 4301 : 4300);
448 ConPuts(StdOut, L"\n\n");
449
450 PrintPaddedMessageString(4424, nPaddedLength);
451 if (pUserInfo->usri4_workstations == NULL || wcslen(pUserInfo->usri4_workstations) == 0)
452 PrintMessageString(4302);
453 else
454 ConPrintf(StdOut, L"%s", pUserInfo->usri4_workstations);
455 ConPuts(StdOut, L"\n");
456
457 PrintPaddedMessageString(4429, nPaddedLength);
458 ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_script_path);
459
460 PrintPaddedMessageString(4439, nPaddedLength);
461 ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_profile);
462
463 PrintPaddedMessageString(4436, nPaddedLength);
464 ConPrintf(StdOut, L"%s\n", pUserInfo->usri4_home_dir);
465
466 PrintPaddedMessageString(4430, nPaddedLength);
467 if (pUserInfo->usri4_last_logon == 0)
468 PrintMessageString(4305);
469 else
471 ConPuts(StdOut, L"\n\n");
472
473 PrintPaddedMessageString(4432, nPaddedLength);
474 if (pUserInfo->usri4_logon_hours == NULL)
475 {
476 PrintMessageString(4302);
477 ConPuts(StdOut, L"\n");
478 }
479 else
480 {
482 pUserInfo->usri4_logon_hours,
483 nPaddedLength);
484 }
485
486 ConPuts(StdOut, L"\n");
487 PrintPaddedMessageString(4427, nPaddedLength);
488 if (dwLocalGroupTotal != 0 && pLocalGroupInfo != NULL)
489 {
490 for (i = 0; i < dwLocalGroupTotal; i++)
491 {
492 if (i != 0)
493 PrintPadding(L' ', nPaddedLength);
494 ConPrintf(StdOut, L"*%s\n", pLocalGroupInfo[i].lgrui0_name);
495 }
496 }
497 else
498 {
499 ConPuts(StdOut, L"\n");
500 }
501
502 PrintPaddedMessageString(4431, nPaddedLength);
503 if (dwGroupTotal != 0 && pGroupInfo != NULL)
504 {
505 for (i = 0; i < dwGroupTotal; i++)
506 {
507 if (i != 0)
508 PrintPadding(L' ', nPaddedLength);
509 ConPrintf(StdOut, L"*%s\n", pGroupInfo[i].grui0_name);
510 }
511 }
512 else
513 {
514 ConPuts(StdOut, L"\n");
515 }
516
517done:
518 if (pGroupInfo != NULL)
519 NetApiBufferFree(pGroupInfo);
520
521 if (pLocalGroupInfo != NULL)
522 NetApiBufferFree(pLocalGroupInfo);
523
524 if (pUserModals != NULL)
525 NetApiBufferFree(pUserModals);
526
527 if (pUserInfo != NULL)
528 NetApiBufferFree(pUserInfo);
529
530 return NERR_Success;
531}
void ConPrintf(FILE *fp, LPCWSTR psz,...)
Definition: fc.c:20
VOID PrintPaddedMessageString(DWORD dwMessage, INT nPaddedLength)
Definition: main.c:143
VOID PrintPadding(WCHAR chr, INT nPaddedLength)
Definition: main.c:63
static VOID PrintLogonHours(DWORD dwUnitsPerWeek, PBYTE pLogonHours, INT nPaddedLength)
Definition: cmdUser.c:257
static DWORD GetTimeInSeconds(VOID)
Definition: cmdUser.c:182
static VOID PrintDateTime(DWORD dwSeconds)
Definition: cmdUser.c:123
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
NET_API_STATUS WINAPI NetUserGetGroups(LPCWSTR servername, LPCWSTR username, DWORD level, LPBYTE *bufptr, DWORD prefixmaxlen, LPDWORD entriesread, LPDWORD totalentries)
Definition: user.c:2982
NET_API_STATUS WINAPI NetUserGetLocalGroups(LPCWSTR servername, LPCWSTR username, DWORD level, DWORD flags, LPBYTE *bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries)
Definition: user.c:3324
NET_API_STATUS WINAPI NetUserModalsGet(LPCWSTR servername, DWORD level, LPBYTE *bufptr)
Definition: user.c:3659
#define UF_DONT_EXPIRE_PASSWD
Definition: lmaccess.h:37
#define UF_LOCKOUT
Definition: lmaccess.h:26
#define MAX_PREFERRED_LENGTH
Definition: lmcons.h:48
DWORD usri4_password_age
Definition: lmaccess.h:272
DWORD usri4_last_logon
Definition: lmaccess.h:283
DWORD usrmod0_min_passwd_age
Definition: lmaccess.h:435
DWORD usrmod0_max_passwd_age
Definition: lmaccess.h:434

Referenced by cmdUser().

◆ EnumerateUsers()

static NET_API_STATUS EnumerateUsers ( VOID  )
static

Definition at line 65 of file cmdUser.c.

66{
68 PSERVER_INFO_100 pServer = NULL;
69 DWORD dwRead = 0, dwTotal = 0;
70 DWORD i;
71 DWORD ResumeHandle = 0;
73
75 100,
76 (LPBYTE*)&pServer);
77 if (Status != NERR_Success)
78 return Status;
79
80 ConPuts(StdOut, L"\n");
81 PrintMessageStringV(4410, pServer->sv100_name);
82 ConPuts(StdOut, L"\n");
83 PrintPadding(L'-', 79);
84 ConPuts(StdOut, L"\n");
85
86 NetApiBufferFree(pServer);
87
88 do
89 {
91 0,
92 0,
93 (LPBYTE*)&pBuffer,
95 &dwRead,
96 &dwTotal,
97 &ResumeHandle);
99 return Status;
100
102 dwRead,
103 sizeof(PUSER_INFO_0),
105
106 for (i = 0; i < dwRead; i++)
107 {
108 if (pBuffer[i].usri0_name)
109 ConPrintf(StdOut, L"%s\n", pBuffer[i].usri0_name);
110 }
111
113 pBuffer = NULL;
114 }
115 while (Status == ERROR_MORE_DATA);
116
117 return NERR_Success;
118}
static int CompareInfo(const void *a, const void *b)
Definition: cmdUser.c:56
#define ERROR_MORE_DATA
Definition: dderror.h:13
NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE *bufptr)
Definition: srvsvc.c:369
NET_API_STATUS WINAPI NetUserEnum(LPCWSTR servername, DWORD level, DWORD filter, LPBYTE *bufptr, DWORD prefmaxlen, LPDWORD entriesread, LPDWORD totalentries, LPDWORD resume_handle)
Definition: user.c:2740
PVOID pBuffer
void __cdecl qsort(_Inout_updates_bytes_(_NumOfElements *_SizeOfElements) void *_Base, _In_ size_t _NumOfElements, _In_ size_t _SizeOfElements, _In_ int(__cdecl *_PtFuncCompare)(const void *, const void *))
LPWSTR sv100_name
Definition: lmserver.h:13

Referenced by cmdUser().

◆ GenerateRandomPassword()

static VOID GenerateRandomPassword ( LPWSTR lpPassword,
LPBOOL  lpAllocated 
)
static

Definition at line 582 of file cmdUser.c.

585{
586 LPWSTR pPassword = NULL;
587 INT nCharsLen, i, nLength = 8;
588
590
591 pPassword = HeapAlloc(GetProcessHeap(),
593 (nLength + 1) * sizeof(WCHAR));
594 if (pPassword == NULL)
595 return;
596
597 nCharsLen = wcslen(szPasswordChars);
598
599 for (i = 0; i < nLength; i++)
600 {
601 pPassword[i] = szPasswordChars[rand() % nCharsLen];
602 }
603
604 *lpPassword = pPassword;
605 *lpAllocated = TRUE;
606}
static WCHAR szPasswordChars[]
Definition: cmdUser.c:25
DWORD WINAPI GetTickCount(VOID)
Definition: time.c:455
void __cdecl srand(_In_ unsigned int _Seed)
_Check_return_ int __cdecl rand(void)
Definition: rand.c:10

Referenced by cmdUser().

◆ GetBitValue()

static BOOL GetBitValue ( PBYTE  pBitmap,
DWORD  dwBitNumber 
)
static

Definition at line 231 of file cmdUser.c.

234{
235 DWORD dwIndex = dwBitNumber / 8;
236 BYTE Mask = 1 << (dwBitNumber & 7);
237
238 return ((pBitmap[dwIndex] & Mask) != 0);
239}
unsigned int Mask
Definition: fpcontrol.c:82
unsigned char BYTE
Definition: xxhash.c:193

Referenced by ParseLogonHours(), and PrintLogonHours().

◆ GetCountryFromCountryCode()

static BOOL GetCountryFromCountryCode ( _In_ DWORD  dwCountryCode,
_In_ DWORD  dwCountryLength,
_Out_ PWSTR  szCountryBuffer 
)
static

Definition at line 199 of file cmdUser.c.

203{
204 DWORD i;
205
206 for (i = 0; i < ARRAYSIZE(CountryTable); i++)
207 {
208 if (CountryTable[i].dwCountryCode == dwCountryCode)
209 {
210 if (szCountryBuffer != NULL && dwCountryLength > 0)
211 {
214 CountryTable[i].dwMessageId,
216 szCountryBuffer,
217 dwCountryLength,
218 NULL);
219 }
220
221 return TRUE;
222 }
223 }
224
225 return FALSE;
226}
HMODULE hModuleNetMsg
Definition: main.c:46
static COUNTRY_TABLE CountryTable[]
Definition: cmdUser.c:26
DWORD WINAPI FormatMessageW(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPWSTR lpBuffer, DWORD nSize, __ms_va_list *args)
Definition: format_msg.c:583
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define FORMAT_MESSAGE_IGNORE_INSERTS
Definition: winbase.h:446
#define FORMAT_MESSAGE_FROM_HMODULE
Definition: winbase.h:448

Referenced by cmdUser(), and DisplayUser().

◆ GetTimeInSeconds()

static DWORD GetTimeInSeconds ( VOID  )
static

Definition at line 182 of file cmdUser.c.

183{
185 FILETIME FileTime;
186 DWORD dwSeconds;
187
188 GetSystemTimeAsFileTime(&FileTime);
189 Time.u.LowPart = FileTime.dwLowDateTime;
190 Time.u.HighPart = FileTime.dwHighDateTime;
191 RtlTimeToSecondsSince1970(&Time, &dwSeconds);
192
193 return dwSeconds;
194}
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
BOOLEAN NTAPI RtlTimeToSecondsSince1970(PLARGE_INTEGER Time, PULONG ElapsedSeconds)
static PLARGE_INTEGER Time
Definition: time.c:105
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65
struct _LARGE_INTEGER::@2303 u

Referenced by DisplayUser().

◆ LocalToGmtHour()

static DWORD LocalToGmtHour ( LONG  lLocalHour,
LONG  lBias 
)
static

Definition at line 914 of file cmdUser.c.

917{
918 LONG lGmtHour;
919
920 lGmtHour = lLocalHour + lBias;
921 if (lGmtHour < 0)
922 lGmtHour += UNITS_PER_WEEK;
923 else if (lGmtHour > UNITS_PER_WEEK)
924 lGmtHour -= UNITS_PER_WEEK;
925
926 return (DWORD)lGmtHour;
927}
#define UNITS_PER_WEEK
Definition: lmaccess.h:114
long LONG
Definition: pedump.c:60

Referenced by ParseLogonHours().

◆ ParseDate()

static BOOL ParseDate ( PWSTR  s,
PULONG  pSeconds 
)
static

Definition at line 746 of file cmdUser.c.

749{
750 SYSTEMTIME SystemTime = {0};
751 FILETIME LocalFileTime, FileTime;
753 INT nDateFormat = 0;
754 PWSTR p = s;
755
756 if (!*s)
757 return FALSE;
758
762 sizeof(INT));
763
764 switch (nDateFormat)
765 {
766 case 0: /* mmddyy */
767 default:
768 if (!ReadNumber(&p, &SystemTime.wMonth))
769 return FALSE;
770 if (!ReadSeparator(&p))
771 return FALSE;
772 if (!ReadNumber(&p, &SystemTime.wDay))
773 return FALSE;
774 if (!ReadSeparator(&p))
775 return FALSE;
776 if (!ReadNumber(&p, &SystemTime.wYear))
777 return FALSE;
778 break;
779
780 case 1: /* ddmmyy */
781 if (!ReadNumber(&p, &SystemTime.wDay))
782 return FALSE;
783 if (!ReadSeparator(&p))
784 return FALSE;
785 if (!ReadNumber(&p, &SystemTime.wMonth))
786 return FALSE;
787 if (!ReadSeparator(&p))
788 return FALSE;
789 if (!ReadNumber(&p, &SystemTime.wYear))
790 return FALSE;
791 break;
792
793 case 2: /* yymmdd */
794 if (!ReadNumber(&p, &SystemTime.wYear))
795 return FALSE;
796 if (!ReadSeparator(&p))
797 return FALSE;
798 if (!ReadNumber(&p, &SystemTime.wMonth))
799 return FALSE;
800 if (!ReadSeparator(&p))
801 return FALSE;
802 if (!ReadNumber(&p, &SystemTime.wDay))
803 return FALSE;
804 break;
805 }
806
807 /* if only entered two digits: */
808 /* assume 2000's if value less than 80 */
809 /* assume 1900's if value greater or equal 80 */
810 if (SystemTime.wYear <= 99)
811 {
812 if (SystemTime.wYear >= 80)
813 SystemTime.wYear += 1900;
814 else
815 SystemTime.wYear += 2000;
816 }
817
818 if (!SystemTimeToFileTime(&SystemTime, &LocalFileTime))
819 return FALSE;
820
821 if (!LocalFileTimeToFileTime(&LocalFileTime, &FileTime))
822 return FALSE;
823
824 Time.u.LowPart = FileTime.dwLowDateTime;
825 Time.u.HighPart = FileTime.dwHighDateTime;
826
827 if (!RtlTimeToSecondsSince1970(&Time, pSeconds))
828 return FALSE;
829
830 return TRUE;
831}
INT nDateFormat
Definition: locale.c:20
static BOOL ReadNumber(PWSTR *s, PWORD pwValue)
Definition: cmdUser.c:712
static BOOL ReadSeparator(PWSTR *s)
Definition: cmdUser.c:731
BOOL WINAPI SystemTimeToFileTime(IN CONST SYSTEMTIME *lpSystemTime, OUT LPFILETIME lpFileTime)
Definition: time.c:158
BOOL WINAPI LocalFileTimeToFileTime(IN CONST FILETIME *lpLocalFileTime, OUT LPFILETIME lpFileTime)
Definition: time.c:253
INT WINAPI GetLocaleInfoW(LCID lcid, LCTYPE lctype, LPWSTR buffer, INT len)
Definition: locale.c:1666
GLdouble s
Definition: gl.h:2039
#define LOCALE_USER_DEFAULT
WORD wYear
Definition: winbase.h:930
WORD wMonth
Definition: winbase.h:931
WORD wDay
Definition: winbase.h:933
#define LOCALE_IDATE
Definition: winnls.h:65

Referenced by cmdUser().

◆ ParseDay()

static BOOL ParseDay ( PWSTR  pszString,
PWSTR ShortDays,
PWSTR LongDays,
PDWORD  pdwDay 
)
static

Definition at line 890 of file cmdUser.c.

895{
896 DWORD i;
897
898 for (i = 0; i < 7; i++)
899 {
900 if (_wcsicmp(pszString, ShortDays[i]) == 0 ||
901 _wcsicmp(pszString, LongDays[i]) == 0)
902 {
903 *pdwDay = i;
904 return TRUE;
905 }
906 }
907
908 return FALSE;
909}
_In_ DWORD _In_ DWORD _Out_writes_to_opt_ pcchString LPSTR pszString
Definition: wincrypt.h:4505

Referenced by ParseLogonHours().

◆ ParseHour()

static BOOL ParseHour ( PWSTR  pszString,
PWSTR AmPmArray,
PLONG  plHour 
)
static

Definition at line 836 of file cmdUser.c.

840{
841 PWCHAR pChar;
842 LONG lHour = 0;
843
844 if (!iswdigit(pszString[0]))
845 return FALSE;
846
847 pChar = pszString;
848 while (iswdigit(*pChar))
849 {
850 lHour = lHour * 10 + *pChar - L'0';
851 pChar++;
852 }
853
854 if (lHour > 24)
855 return FALSE;
856
857 if (lHour == 24)
858 lHour = 0;
859
860 if ((*pChar != UNICODE_NULL) &&
861 (lHour >= 1) &&
862 (lHour <= 12))
863 {
864 if ((_wcsicmp(pChar, AmPmArray[0]) == 0) ||
865 (_wcsicmp(pChar, AmPmArray[1]) == 0))
866 {
867 if (lHour == 12)
868 lHour = 0;
869 }
870 else if ((_wcsicmp(pChar, AmPmArray[2]) == 0) ||
871 (_wcsicmp(pChar, AmPmArray[3]) == 0))
872 {
873 if (lHour != 12)
874 lHour += 12;
875 }
876 else
877 {
878 return FALSE;
879 }
880 }
881
882 *plHour = lHour;
883
884 return TRUE;
885}
#define iswdigit(_c)
Definition: ctype.h:667
#define UNICODE_NULL
uint16_t * PWCHAR
Definition: typedefs.h:56

Referenced by ParseLogonHours().

◆ ParseLogonHours()

static DWORD ParseLogonHours ( PWSTR  pszParams,
PBYTE ppLogonBitmap,
PDWORD  pdwUnitsPerWeek 
)
static

Definition at line 932 of file cmdUser.c.

936{
937 TIME_ZONE_INFORMATION TimeZoneInformation;
938 PBYTE pLogonBitmap = NULL;
939 DWORD dwError = ERROR_SUCCESS;
940 WCHAR szBuffer[32];
941 PWSTR ptr1, ptr2;
942 WCHAR prevSep, nextSep;
943 DWORD dwStartDay, dwEndDay, i, j;
944 LONG lStartHour, lEndHour, lBias;
945 BYTE DayBitmap;
946 BYTE HourBitmap[6];
947 LPWSTR ShortDays[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
948 LPWSTR LongDays[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL};
949 LPWSTR AmPmArray[4] = {NULL, NULL, NULL, NULL};
950
951 GetTimeZoneInformation(&TimeZoneInformation);
952 lBias = TimeZoneInformation.Bias / 60;
953
954 pLogonBitmap = HeapAlloc(GetProcessHeap(),
956 UNITS_PER_WEEK / 8);
957 if (pLogonBitmap == NULL)
958 return ERROR_OUTOFMEMORY;
959
960 if (*pszParams == UNICODE_NULL)
961 {
962 goto done;
963 }
964
965 if (_wcsicmp(pszParams, L"all") == 0)
966 {
967 FillMemory(pLogonBitmap, UNITS_PER_WEEK / 8, 0xFF);
968 goto done;
969 }
970
971 for (i = 0; i < 7; i++)
972 {
977 4314 + i,
979 (LPWSTR)&ShortDays[i],
980 0,
981 NULL);
982
987 4307 + i,
989 (LPWSTR)&LongDays[i],
990 0,
991 NULL);
992 }
993
994 for (i = 0; i < 4; i++)
995 {
1000 4322 + i,
1002 (LPWSTR)&AmPmArray[i],
1003 0,
1004 NULL);
1005 }
1006
1007 ZeroMemory(&DayBitmap, sizeof(DayBitmap));
1008 ZeroMemory(HourBitmap, sizeof(HourBitmap));
1009
1010 ZeroMemory(szBuffer, sizeof(szBuffer));
1011 ptr1 = pszParams;
1012 ptr2 = szBuffer;
1013 prevSep = UNICODE_NULL;
1014 nextSep = UNICODE_NULL;
1015 for (;;)
1016 {
1017 if (*ptr1 != L'-' && *ptr1 != L',' && *ptr1 != L';' && *ptr1 != UNICODE_NULL)
1018 {
1019 *ptr2 = *ptr1;
1020 ptr2++;
1021 }
1022 else
1023 {
1024 prevSep = nextSep;
1025 nextSep = *ptr1;
1026
1027 if (prevSep != L'-')
1028 {
1029 /* Set first value */
1030 if (iswdigit(szBuffer[0]))
1031 {
1032 /* Parse hour */
1033 if (!ParseHour(szBuffer, AmPmArray, &lStartHour))
1034 {
1035 dwError = 3769;
1036 break;
1037 }
1038
1039 SetBitValue(HourBitmap, LocalToGmtHour(lStartHour, lBias));
1040 }
1041 else
1042 {
1043 /* Parse day */
1044 if (!ParseDay(szBuffer, ShortDays, LongDays, &dwStartDay))
1045 {
1046 dwError = 3768;
1047 break;
1048 }
1049
1050 SetBitValue(&DayBitmap, dwStartDay);
1051 }
1052 }
1053 else
1054 {
1055 /* Set second value */
1056 if (iswdigit(szBuffer[0]))
1057 {
1058 /* Parse hour */
1059 if (!ParseHour(szBuffer, AmPmArray, &lEndHour))
1060 {
1061 dwError = 3769;
1062 break;
1063 }
1064
1065 if (lEndHour <= lStartHour)
1066 lEndHour += HOURS_PER_DAY;
1067
1068 for (i = LocalToGmtHour(lStartHour, lBias); i < LocalToGmtHour(lEndHour, lBias); i++)
1069 SetBitValue(HourBitmap, i);
1070 }
1071 else
1072 {
1073 /* Parse day */
1074 if (!ParseDay(szBuffer, ShortDays, LongDays, &dwEndDay))
1075 {
1076 dwError = 3768;
1077 break;
1078 }
1079
1080 if (dwEndDay <= dwStartDay)
1081 dwEndDay += DAYS_PER_WEEK;
1082
1083 for (i = dwStartDay; i <= dwEndDay; i++)
1084 SetBitValue(&DayBitmap, i % DAYS_PER_WEEK);
1085 }
1086 }
1087
1088 if (*ptr1 == L';' || *ptr1 == UNICODE_NULL)
1089 {
1090 /* Fill the logon hour bitmap */
1091 for (i = 0; i < DAYS_PER_WEEK; i++)
1092 {
1093 if (GetBitValue(&DayBitmap, i))
1094 {
1095 for (j = 0; j < 48; j++)
1096 {
1097 if (GetBitValue(HourBitmap, j))
1098 SetBitValue(pLogonBitmap, ((i * HOURS_PER_DAY) + j) % UNITS_PER_WEEK);
1099 }
1100 }
1101 }
1102
1103 /* Reset the Bitmaps */
1104 ZeroMemory(&DayBitmap, sizeof(DayBitmap));
1105 ZeroMemory(HourBitmap, sizeof(HourBitmap));
1106 }
1107
1108 if (*ptr1 == UNICODE_NULL)
1109 break;
1110
1111 ZeroMemory(szBuffer, sizeof(szBuffer));
1112 ptr2 = szBuffer;
1113 }
1114
1115 ptr1++;
1116 }
1117
1118done:
1119 for (i = 0; i < 7; i++)
1120 {
1121 LocalFree(ShortDays[i]);
1122 LocalFree(LongDays[i]);
1123 }
1124
1125 for (i = 0; i < 4; i++)
1126 {
1127 LocalFree(AmPmArray[i]);
1128 }
1129
1130 if (dwError == ERROR_SUCCESS)
1131 {
1132 *ppLogonBitmap = pLogonBitmap;
1133 *pdwUnitsPerWeek = UNITS_PER_WEEK;
1134 }
1135 else
1136 {
1137 if (pLogonBitmap != NULL)
1138 HeapFree(GetProcessHeap(), 0, pLogonBitmap);
1139 *ppLogonBitmap = NULL;
1140 *pdwUnitsPerWeek = 0;
1141 }
1142
1143 return dwError;
1144}
static DWORD LocalToGmtHour(LONG lLocalHour, LONG lBias)
Definition: cmdUser.c:914
static BOOL ParseHour(PWSTR pszString, PWSTR *AmPmArray, PLONG plHour)
Definition: cmdUser.c:836
static VOID SetBitValue(PBYTE pBitmap, DWORD dwBitNumber)
Definition: cmdUser.c:244
static BOOL GetBitValue(PBYTE pBitmap, DWORD dwBitNumber)
Definition: cmdUser.c:231
#define HOURS_PER_DAY
Definition: cmdUser.c:15
#define DAYS_PER_WEEK
Definition: cmdUser.c:16
static BOOL ParseDay(PWSTR pszString, PWSTR *ShortDays, PWSTR *LongDays, PDWORD pdwDay)
Definition: cmdUser.c:890
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION lpTimeZoneInformation)
Definition: timezone.c:262
#define FillMemory(BUF, SIZ, MASK)
Definition: strucsup.c:31
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1594
#define FORMAT_MESSAGE_ALLOCATE_BUFFER
Definition: winbase.h:445

Referenced by cmdUser().

◆ PrintDateTime()

static VOID PrintDateTime ( DWORD  dwSeconds)
static

Definition at line 123 of file cmdUser.c.

124{
126 FILETIME FileTime;
127 SYSTEMTIME SystemTime;
128 WCHAR DateBuffer[80];
129 WCHAR TimeBuffer[80];
130
131 RtlSecondsSince1970ToTime(dwSeconds, &Time);
132 FileTime.dwLowDateTime = Time.u.LowPart;
133 FileTime.dwHighDateTime = Time.u.HighPart;
134 FileTimeToLocalFileTime(&FileTime, &FileTime);
135 FileTimeToSystemTime(&FileTime, &SystemTime);
136
139 &SystemTime,
140 NULL,
141 DateBuffer,
142 ARRAYSIZE(DateBuffer));
143
146 &SystemTime,
147 NULL,
148 TimeBuffer,
149 ARRAYSIZE(TimeBuffer));
150
151 ConPrintf(StdOut, L"%s %s", DateBuffer, TimeBuffer);
152}
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:188
BOOL WINAPI FileTimeToLocalFileTime(IN CONST FILETIME *lpFileTime, OUT LPFILETIME lpLocalFileTime)
Definition: time.c:221
INT WINAPI GetTimeFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, INT cchOut)
Definition: lcformat.c:1093
INT WINAPI GetDateFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpDateStr, INT cchOut)
Definition: lcformat.c:993
NTSYSAPI VOID NTAPI RtlSecondsSince1970ToTime(_In_ ULONG SecondsSince1970, _Out_ PLARGE_INTEGER Time)
#define TIME_NOSECONDS
Definition: winnls.h:280
#define DATE_SHORTDATE
Definition: winnls.h:198

Referenced by DisplayUser().

◆ PrintLocalTime()

static VOID PrintLocalTime ( DWORD  dwSeconds)
static

Definition at line 157 of file cmdUser.c.

158{
160 FILETIME FileTime;
161 SYSTEMTIME SystemTime;
162 WCHAR TimeBuffer[80];
163
164 RtlSecondsSince1970ToTime(dwSeconds, &Time);
165 FileTime.dwLowDateTime = Time.u.LowPart;
166 FileTime.dwHighDateTime = Time.u.HighPart;
167 FileTimeToSystemTime(&FileTime, &SystemTime);
168
171 &SystemTime,
172 NULL,
173 TimeBuffer,
174 ARRAYSIZE(TimeBuffer));
175
176 ConPrintf(StdOut, L"%s", TimeBuffer);
177}

Referenced by PrintLogonHours().

◆ PrintLogonHours()

static VOID PrintLogonHours ( DWORD  dwUnitsPerWeek,
PBYTE  pLogonHours,
INT  nPaddedLength 
)
static

Definition at line 257 of file cmdUser.c.

261{
262 DWORD dwUnitsPerDay, dwBitNumber, dwSecondsPerUnit;
263 DWORD dwStartTime, dwEndTime, dwStartDay, dwEndDay, dwBias;
264 BOOL bBitValue, bFirst = TRUE;
265 TIME_ZONE_INFORMATION TimeZoneInformation;
266
267 GetTimeZoneInformation(&TimeZoneInformation);
268 dwBias = (TimeZoneInformation.Bias / 60) * SECONDS_PER_HOUR;
269
270 if ((dwUnitsPerWeek == 0) ||
271 ((dwUnitsPerWeek %7) != 0))
272 return;
273
274 dwUnitsPerDay = dwUnitsPerWeek / 7;
275
276 if (((dwUnitsPerDay % 24) != 0) ||
277 ((dwUnitsPerDay / 24) > 6))
278 return;
279
280 dwSecondsPerUnit = (SECONDS_PER_DAY) / dwUnitsPerDay;
281
282 for (dwBitNumber = 0; dwBitNumber < dwUnitsPerWeek; dwBitNumber++)
283 {
284 bBitValue = GetBitValue(pLogonHours, dwBitNumber);
285 if (bBitValue)
286 {
287 dwStartTime = dwSecondsPerUnit * dwBitNumber;
288
289 while (bBitValue != 0 && dwBitNumber < dwUnitsPerWeek)
290 {
291 dwBitNumber++;
292 if (dwBitNumber < dwUnitsPerWeek)
293 bBitValue = GetBitValue(pLogonHours, dwBitNumber);
294 }
295
296 dwEndTime = dwSecondsPerUnit * dwBitNumber;
297
298 if (!bFirst)
299 PrintPadding(L' ', nPaddedLength);
300
301 if (dwStartTime == 0 && dwEndTime == (SECONDS_PER_DAY * 7))
302 {
303 PrintMessageString(4302);
304 ConPuts(StdOut, L"\n");
305 }
306 else
307 {
308 dwStartDay = dwStartTime / SECONDS_PER_DAY;
309 dwEndDay = (dwEndTime / SECONDS_PER_DAY) % 7;
310
311 PrintMessageString(4307 + dwStartDay);
312 ConPuts(StdOut, L" ");
313
314 /* Convert from GMT to local timezone */
315 PrintLocalTime((dwStartTime % SECONDS_PER_DAY) - dwBias);
316
317 ConPrintf(StdOut, L" - ");
318 if (dwStartDay != dwEndDay)
319 {
320 PrintMessageString(4307 + dwEndDay);
321 ConPuts(StdOut, L" ");
322 }
323
324 /* Convert from GMT to local timezone */
325 PrintLocalTime((dwEndTime % SECONDS_PER_DAY) - dwBias);
326 ConPuts(StdOut, L"\n");
327 }
328
329 bFirst = FALSE;
330 }
331 }
332
333 if (bFirst)
334 {
335 /* No logon hours */
336 PrintMessageString(4434);
337 ConPuts(StdOut, L"\n");
338 }
339}
static VOID PrintLocalTime(DWORD dwSeconds)
Definition: cmdUser.c:157
#define SECONDS_PER_DAY
Definition: cmdUser.c:13
#define SECONDS_PER_HOUR
Definition: cmdUser.c:14

Referenced by DisplayUser().

◆ ReadNumber()

static BOOL ReadNumber ( PWSTR s,
PWORD  pwValue 
)
static

Definition at line 712 of file cmdUser.c.

715{
716 if (!iswdigit(**s))
717 return FALSE;
718
719 while (iswdigit(**s))
720 {
721 *pwValue = *pwValue * 10 + **s - L'0';
722 (*s)++;
723 }
724
725 return TRUE;
726}

Referenced by ParseDate().

◆ ReadPassword()

static VOID ReadPassword ( LPWSTR lpPassword,
LPBOOL  lpAllocated 
)
static

Definition at line 536 of file cmdUser.c.

539{
540 WCHAR szPassword1[PWLEN + 1];
541 WCHAR szPassword2[PWLEN + 1];
542 LPWSTR ptr;
543
544 *lpAllocated = FALSE;
545
546 while (TRUE)
547 {
548 PrintMessageString(4358);
549 ReadFromConsole(szPassword1, PWLEN + 1, FALSE);
550 ConPuts(StdOut, L"\n");
551
552 PrintMessageString(4361);
553 ReadFromConsole(szPassword2, PWLEN + 1, FALSE);
554 ConPuts(StdOut, L"\n");
555
556 if (wcslen(szPassword1) == wcslen(szPassword2) &&
557 wcscmp(szPassword1, szPassword2) == 0)
558 {
560 0,
561 (wcslen(szPassword1) + 1) * sizeof(WCHAR));
562 if (ptr != NULL)
563 {
564 wcscpy(ptr, szPassword1);
565 *lpPassword = ptr;
566 *lpAllocated = TRUE;
567 return;
568 }
569 }
570 else
571 {
572 ConPuts(StdOut, L"\n");
573 PrintMessageString(3728);
574 *lpPassword = NULL;
575 }
576 }
577}
VOID ReadFromConsole(LPWSTR lpInput, DWORD dwLength, BOOL bEcho)
Definition: main.c:264
#define PWLEN
Definition: lmcons.h:37
static PVOID ptr
Definition: dispmode.c:27
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)

Referenced by cmdUser().

◆ ReadSeparator()

static BOOL ReadSeparator ( PWSTR s)
static

Definition at line 731 of file cmdUser.c.

733{
734 if (**s == L'/' || **s == L'.')
735 {
736 (*s)++;
737 return TRUE;
738 }
739
740 return FALSE;
741}

Referenced by ParseDate().

◆ SetBitValue()

static VOID SetBitValue ( PBYTE  pBitmap,
DWORD  dwBitNumber 
)
static

Definition at line 244 of file cmdUser.c.

247{
248 DWORD dwIndex = dwBitNumber / 8;
249 BYTE Mask = 1 << (dwBitNumber & 7);
250
251 pBitmap[dwIndex] |= Mask;
252}

Referenced by ParseLogonHours().

Variable Documentation

◆ CountryTable

COUNTRY_TABLE CountryTable[]
static
Initial value:
=
{ { 0, 5080},
{ 1, 5081},
{ 2, 5082},
{ 3, 5083},
{ 31, 5084},
{ 32, 5085},
{ 33, 5086},
{ 34, 5090},
{ 39, 5087},
{ 41, 5088},
{ 44, 5089},
{ 45, 5091},
{ 46, 5092},
{ 47, 5093},
{ 49, 5094},
{ 61, 5095},
{ 81, 5096},
{ 82, 5097},
{ 86, 5098},
{ 88, 5099},
{ 99, 5100},
{351, 5101},
{358, 5102},
{785, 5103},
{972, 5104} }

Definition at line 26 of file cmdUser.c.

Referenced by GetCountryFromCountryCode().

◆ szPasswordChars

WCHAR szPasswordChars[] = L"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ@#$%_-+:"
static

Definition at line 25 of file cmdUser.c.

Referenced by GenerateRandomPassword().