2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
7 * PROGRAMMERS: Eric Kohl
15 CompareInfo(const void *a
,
18 return _wcsicmp(((PUSER_INFO_0
)a
)->usri0_name
,
19 ((PUSER_INFO_0
)b
)->usri0_name
);
27 PUSER_INFO_0 pBuffer
= NULL
;
28 PSERVER_INFO_100 pServer
= NULL
;
29 DWORD dwRead
= 0, dwTotal
= 0;
31 DWORD_PTR ResumeHandle
= 0;
32 NET_API_STATUS Status
;
34 Status
= NetServerGetInfo(NULL
,
37 if (Status
!= NERR_Success
)
40 PrintToConsole(L
"\nUser accounts for \\\\%s\n\n", pServer
->sv100_name
);
42 NetApiBufferFree(pServer
);
44 PrintToConsole(L
"------------------------------------------\n");
46 Status
= NetUserEnum(NULL
,
54 if (Status
!= NERR_Success
)
62 // printf("dwRead: %lu dwTotal: %lu\n", dwRead, dwTotal);
63 for (i
= 0; i
< dwRead
; i
++)
65 // printf("%p\n", pBuffer[i].lgrpi0_name);
66 if (pBuffer
[i
].usri0_name
)
67 PrintToConsole(L
"%s\n", pBuffer
[i
].usri0_name
);
70 NetApiBufferFree(pBuffer
);
78 PrintDateTime(DWORD dwSeconds
)
82 SYSTEMTIME SystemTime
;
86 RtlSecondsSince1970ToTime(dwSeconds
, &Time
);
87 FileTime
.dwLowDateTime
= Time
.u
.LowPart
;
88 FileTime
.dwHighDateTime
= Time
.u
.HighPart
;
89 FileTimeToLocalFileTime(&FileTime
, &FileTime
);
90 FileTimeToSystemTime(&FileTime
, &SystemTime
);
92 GetDateFormatW(LOCALE_USER_DEFAULT
,
99 GetTimeFormatW(LOCALE_USER_DEFAULT
,
106 PrintToConsole(L
"%s %s\n", DateBuffer
, TimeBuffer
);
112 GetTimeInSeconds(VOID
)
118 GetSystemTimeAsFileTime(&FileTime
);
119 Time
.u
.LowPart
= FileTime
.dwLowDateTime
;
120 Time
.u
.HighPart
= FileTime
.dwHighDateTime
;
121 RtlTimeToSecondsSince1970(&Time
, &dwSeconds
);
129 DisplayUser(LPWSTR lpUserName
)
131 PUSER_MODALS_INFO_0 pUserModals
= NULL
;
132 PUSER_INFO_4 pUserInfo
= NULL
;
134 NET_API_STATUS Status
;
136 /* Modify the user */
137 Status
= NetUserGetInfo(NULL
,
140 (LPBYTE
*)&pUserInfo
);
141 if (Status
!= NERR_Success
)
144 Status
= NetUserModalsGet(NULL
,
146 (LPBYTE
*)&pUserModals
);
147 if (Status
!= NERR_Success
)
150 PrintToConsole(L
"User name %s\n", pUserInfo
->usri4_name
);
151 PrintToConsole(L
"Full name %s\n", pUserInfo
->usri4_full_name
);
152 PrintToConsole(L
"Comment %s\n", pUserInfo
->usri4_comment
);
153 PrintToConsole(L
"User comment %s\n", pUserInfo
->usri4_usr_comment
);
154 PrintToConsole(L
"Country code %03ld ()\n", pUserInfo
->usri4_country_code
);
155 PrintToConsole(L
"Account active %s\n", (pUserInfo
->usri4_flags
& UF_ACCOUNTDISABLE
)? L
"No" : ((pUserInfo
->usri4_flags
& UF_LOCKOUT
) ? L
"Locked" : L
"Yes"));
156 PrintToConsole(L
"Account expires ");
157 if (pUserInfo
->usri4_acct_expires
== TIMEQ_FOREVER
)
158 PrintToConsole(L
"Never\n");
160 PrintDateTime(pUserInfo
->usri4_acct_expires
);
162 PrintToConsole(L
"\n");
164 PrintToConsole(L
"Password expires ");
165 dwLastSet
= GetTimeInSeconds() - pUserInfo
->usri4_password_age
;
166 PrintDateTime(dwLastSet
);
168 PrintToConsole(L
"Password expires ");
169 if ((pUserInfo
->usri4_flags
& UF_DONT_EXPIRE_PASSWD
) || pUserModals
->usrmod0_max_passwd_age
== TIMEQ_FOREVER
)
170 PrintToConsole(L
"Never\n");
172 PrintDateTime(dwLastSet
+ pUserModals
->usrmod0_max_passwd_age
);
174 PrintToConsole(L
"Password changeable ");
175 PrintDateTime(dwLastSet
+ pUserModals
->usrmod0_min_passwd_age
);
177 PrintToConsole(L
"Password required %s\n", (pUserInfo
->usri4_flags
& UF_PASSWD_NOTREQD
) ? L
"No" : L
"Yes");
178 PrintToConsole(L
"User may change password %s\n", (pUserInfo
->usri4_flags
& UF_PASSWD_CANT_CHANGE
) ? L
"No" : L
"Yes");
180 PrintToConsole(L
"\n");
181 PrintToConsole(L
"Workstation allowed %s\n", pUserInfo
->usri4_workstations
);
182 PrintToConsole(L
"Logon script %s\n", pUserInfo
->usri4_script_path
);
183 PrintToConsole(L
"User profile %s\n", pUserInfo
->usri4_profile
);
184 PrintToConsole(L
"Home directory %s\n", pUserInfo
->usri4_home_dir
);
185 PrintToConsole(L
"Last logon ");
186 if (pUserInfo
->usri4_last_logon
== 0)
187 PrintToConsole(L
"Never\n");
189 PrintDateTime(pUserInfo
->usri4_last_logon
);
190 PrintToConsole(L
"\n");
191 PrintToConsole(L
"Logon hours allowed \n");
192 PrintToConsole(L
"\n");
193 PrintToConsole(L
"Local group memberships \n");
194 PrintToConsole(L
"Global group memberships \n");
197 if (pUserModals
!= NULL
)
198 NetApiBufferFree(pUserModals
);
200 if (pUserInfo
!= NULL
)
201 NetApiBufferFree(pUserInfo
);
215 BOOL bDelete
= FALSE
;
217 BOOL bDomain
= FALSE
;
219 LPWSTR lpUserName
= NULL
;
220 LPWSTR lpPassword
= NULL
;
221 PUSER_INFO_4 pUserInfo
= NULL
;
222 USER_INFO_4 UserInfo
;
224 NET_API_STATUS Status
;
228 Status
= EnumerateUsers();
229 printf("Status: %lu\n", Status
);
234 Status
= DisplayUser(argv
[2]);
235 printf("Status: %lu\n", Status
);
240 if (argv
[i
][0] != L
'/')
242 lpUserName
= argv
[i
];
243 printf("User: %S\n", lpUserName
);
247 if (argv
[i
][0] != L
'/')
249 lpPassword
= argv
[i
];
250 printf("Password: %S\n", lpPassword
);
254 for (j
= i
; j
< argc
; j
++)
256 if (_wcsicmp(argv
[j
], L
"/help") == 0)
258 PrintResourceString(IDS_USER_HELP
);
261 else if (_wcsicmp(argv
[j
], L
"/add") == 0)
265 else if (_wcsicmp(argv
[j
], L
"/delete") == 0)
269 else if (_wcsicmp(argv
[j
], L
"/domain") == 0)
271 printf("The /DOMAIN option is not supported yet!\n");
284 if (!bAdd
&& !bDelete
)
286 /* Modify the user */
287 Status
= NetUserGetInfo(NULL
,
290 (LPBYTE
*)&pUserInfo
);
291 printf("Status: %lu\n", Status
);
293 else if (bAdd
&& !bDelete
)
296 ZeroMemory(&UserInfo
, sizeof(USER_INFO_4
));
298 UserInfo
.usri4_name
= lpUserName
;
299 UserInfo
.usri4_password
= lpPassword
;
300 UserInfo
.usri4_flags
= UF_SCRIPT
| UF_NORMAL_ACCOUNT
;
302 pUserInfo
= &UserInfo
;
305 for (j
= i
; j
< argc
; j
++)
307 if (_wcsnicmp(argv
[j
], L
"/active:", 8) == 0)
310 if (_wcsicmp(p
, L
"yes") == 0)
314 else if (_wcsicmp(p
, L
"no") == 0)
320 PrintToConsole(L
"You entered an invalid value for the /ACTIVE option.\n");
325 else if (_wcsnicmp(argv
[j
], L
"/comment:", 9) == 0)
327 pUserInfo
->usri4_comment
= &argv
[j
][9];
329 else if (_wcsnicmp(argv
[j
], L
"/countrycode:", 13) == 0)
332 else if (_wcsnicmp(argv
[j
], L
"/expires:", 9) == 0)
335 else if (_wcsnicmp(argv
[j
], L
"/fullname:", 10) == 0)
337 pUserInfo
->usri4_full_name
= &argv
[j
][10];
339 else if (_wcsnicmp(argv
[j
], L
"/homedir:", 9) == 0)
341 pUserInfo
->usri4_home_dir
= &argv
[j
][9];
343 else if (_wcsnicmp(argv
[j
], L
"/passwordchg:", 13) == 0)
346 else if (_wcsnicmp(argv
[j
], L
"/passwordreq:", 13) == 0)
349 else if (_wcsnicmp(argv
[j
], L
"/profilepath:", 13) == 0)
351 pUserInfo
->usri4_profile
= &argv
[j
][13];
353 else if (_wcsnicmp(argv
[j
], L
"/scriptpath:", 12) == 0)
355 pUserInfo
->usri4_script_path
= &argv
[j
][12];
357 else if (_wcsnicmp(argv
[j
], L
"/times:", 7) == 0)
360 else if (_wcsnicmp(argv
[j
], L
"/usercomment:", 13) == 0)
362 pUserInfo
->usri4_usr_comment
= &argv
[j
][13];
364 else if (_wcsnicmp(argv
[j
], L
"/workstations:", 14) == 0)
369 if (!bAdd
&& !bDelete
)
371 /* Modify the user */
372 Status
= NetUserSetInfo(NULL
,
377 printf("Status: %lu\n", Status
);
379 else if (bAdd
&& !bDelete
)
382 Status
= NetUserAdd(NULL
,
386 printf("Status: %lu\n", Status
);
388 else if (!bAdd
&& bDelete
)
390 /* Delete the user */
391 Status
= NetUserDel(NULL
,
393 printf("Status: %lu\n", Status
);
397 if (!bAdd
&& !bDelete
&& pUserInfo
!= NULL
)
398 NetApiBufferFree(pUserInfo
);
401 PrintResourceString(IDS_USER_SYNTAX
);