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 FileTimeToSystemTime(&FileTime
, &SystemTime
);
91 GetDateFormatW(LOCALE_USER_DEFAULT
,
98 GetTimeFormatW(LOCALE_USER_DEFAULT
,
105 PrintToConsole(L
"%s %s\n", DateBuffer
, TimeBuffer
);
111 DisplayUser(LPWSTR lpUserName
)
113 PUSER_MODALS_INFO_0 pUserModals
= NULL
;
114 PUSER_INFO_4 pUserInfo
= NULL
;
115 NET_API_STATUS Status
;
117 /* Modify the user */
118 Status
= NetUserGetInfo(NULL
,
121 (LPBYTE
*)&pUserInfo
);
122 if (Status
!= NERR_Success
)
125 Status
= NetUserModalsGet(NULL
,
127 (LPBYTE
*)&pUserModals
);
128 if (Status
!= NERR_Success
)
131 PrintToConsole(L
"User name %s\n", pUserInfo
->usri4_name
);
132 PrintToConsole(L
"Full name %s\n", pUserInfo
->usri4_full_name
);
133 PrintToConsole(L
"Comment %s\n", pUserInfo
->usri4_comment
);
134 PrintToConsole(L
"User comment %s\n", pUserInfo
->usri4_usr_comment
);
135 PrintToConsole(L
"Country code %03ld ()\n", pUserInfo
->usri4_country_code
);
136 PrintToConsole(L
"Account active %s\n", (pUserInfo
->usri4_flags
& UF_ACCOUNTDISABLE
)? L
"No" : ((pUserInfo
->usri4_flags
& UF_LOCKOUT
) ? L
"Locked" : L
"Yes"));
137 PrintToConsole(L
"Account expires ");
138 if (pUserInfo
->usri4_acct_expires
== TIMEQ_FOREVER
)
139 PrintToConsole(L
"Never\n");
141 PrintDateTime(pUserInfo
->usri4_acct_expires
);
143 PrintToConsole(L
"\n");
144 PrintToConsole(L
"Password last set \n");
146 PrintToConsole(L
"Password expires ");
147 if (pUserModals
->usrmod0_max_passwd_age
== TIMEQ_FOREVER
)
148 PrintToConsole(L
"Never\n");
150 PrintDateTime(pUserInfo
->usri4_acct_expires
);
152 PrintToConsole(L
"Password changeable \n");
153 PrintToConsole(L
"Password required \n");
154 PrintToConsole(L
"User may change password \n");
156 PrintToConsole(L
"\n");
157 PrintToConsole(L
"Workstation allowed %s\n", pUserInfo
->usri4_workstations
);
158 PrintToConsole(L
"Logon script %s\n", pUserInfo
->usri4_script_path
);
159 PrintToConsole(L
"User profile %s\n", pUserInfo
->usri4_profile
);
160 PrintToConsole(L
"Home directory %s\n", pUserInfo
->usri4_home_dir
);
161 PrintToConsole(L
"Last logon ");
162 if (pUserInfo
->usri4_last_logon
== 0)
163 PrintToConsole(L
"Never\n");
165 PrintDateTime(pUserInfo
->usri4_last_logon
);
166 PrintToConsole(L
"\n");
167 PrintToConsole(L
"Logon hours allowed \n");
168 PrintToConsole(L
"\n");
169 PrintToConsole(L
"Local group memberships \n");
170 PrintToConsole(L
"Global group memberships \n");
173 if (pUserModals
!= NULL
)
174 NetApiBufferFree(pUserModals
);
176 if (pUserInfo
!= NULL
)
177 NetApiBufferFree(pUserInfo
);
191 BOOL bDelete
= FALSE
;
193 BOOL bDomain
= FALSE
;
195 LPWSTR lpUserName
= NULL
;
196 LPWSTR lpPassword
= NULL
;
197 PUSER_INFO_4 pUserInfo
= NULL
;
198 USER_INFO_4 UserInfo
;
199 NET_API_STATUS Status
;
203 Status
= EnumerateUsers();
204 printf("Status: %lu\n", Status
);
209 Status
= DisplayUser(argv
[2]);
210 printf("Status: %lu\n", Status
);
215 if (argv
[i
][0] != L
'/')
217 lpUserName
= argv
[i
];
218 printf("User: %S\n", lpUserName
);
222 if (argv
[i
][0] != L
'/')
224 lpPassword
= argv
[i
];
225 printf("Password: %S\n", lpPassword
);
229 for (j
= i
; j
< argc
; j
++)
231 if (_wcsicmp(argv
[j
], L
"/help") == 0)
233 PrintResourceString(IDS_USER_HELP
);
236 else if (_wcsicmp(argv
[j
], L
"/add") == 0)
240 else if (_wcsicmp(argv
[j
], L
"/delete") == 0)
244 else if (_wcsicmp(argv
[j
], L
"/domain") == 0)
246 printf("The /DOMAIN option is not supported yet!\n");
259 if (!bAdd
&& !bDelete
)
261 /* Modify the user */
262 Status
= NetUserGetInfo(NULL
,
265 (LPBYTE
*)&pUserInfo
);
266 printf("Status: %lu\n", Status
);
268 else if (bAdd
&& !bDelete
)
271 ZeroMemory(&UserInfo
, sizeof(USER_INFO_4
));
273 UserInfo
.usri4_name
= lpUserName
;
274 UserInfo
.usri4_password
= lpPassword
;
275 UserInfo
.usri4_flags
= UF_SCRIPT
| UF_NORMAL_ACCOUNT
;
277 pUserInfo
= &UserInfo
;
280 for (j
= i
; j
< argc
; j
++)
282 if (_wcsnicmp(argv
[j
], L
"/active:", 8) == 0)
285 else if (_wcsnicmp(argv
[j
], L
"/comment:", 9) == 0)
287 pUserInfo
->usri4_comment
= &argv
[j
][9];
289 else if (_wcsnicmp(argv
[j
], L
"/countrycode:", 13) == 0)
292 else if (_wcsnicmp(argv
[j
], L
"/expires:", 9) == 0)
295 else if (_wcsnicmp(argv
[j
], L
"/fullname:", 10) == 0)
297 pUserInfo
->usri4_full_name
= &argv
[j
][10];
299 else if (_wcsnicmp(argv
[j
], L
"/homedir:", 9) == 0)
301 pUserInfo
->usri4_home_dir
= &argv
[j
][9];
303 else if (_wcsnicmp(argv
[j
], L
"/passwordchg:", 13) == 0)
306 else if (_wcsnicmp(argv
[j
], L
"/passwordreq:", 13) == 0)
309 else if (_wcsnicmp(argv
[j
], L
"/profilepath:", 13) == 0)
311 pUserInfo
->usri4_profile
= &argv
[j
][13];
313 else if (_wcsnicmp(argv
[j
], L
"/scriptpath:", 12) == 0)
315 pUserInfo
->usri4_script_path
= &argv
[j
][12];
317 else if (_wcsnicmp(argv
[j
], L
"/times:", 7) == 0)
320 else if (_wcsnicmp(argv
[j
], L
"/usercomment:", 13) == 0)
322 pUserInfo
->usri4_usr_comment
= &argv
[j
][13];
324 else if (_wcsnicmp(argv
[j
], L
"/workstations:", 14) == 0)
329 if (!bAdd
&& !bDelete
)
331 /* Modify the user */
332 Status
= NetUserSetInfo(NULL
,
337 printf("Status: %lu\n", Status
);
339 else if (bAdd
&& !bDelete
)
342 Status
= NetUserAdd(NULL
,
346 printf("Status: %lu\n", Status
);
348 else if (!bAdd
&& bDelete
)
350 /* Delete the user */
351 Status
= NetUserDel(NULL
,
353 printf("Status: %lu\n", Status
);
357 if (!bAdd
&& !bDelete
&& pUserInfo
!= NULL
)
358 NetApiBufferFree(pUserInfo
);
361 PrintResourceString(IDS_USER_SYNTAX
);