Sync to trunk r65566.
[reactos.git] / base / applications / network / net / cmdAccounts.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS net command
4 * FILE:
5 * PURPOSE:
6 *
7 * PROGRAMMERS: Eric Kohl
8 */
9
10 #include "net.h"
11
12 INT
13 cmdAccounts(
14 INT argc,
15 WCHAR **argv)
16 {
17 PUSER_MODALS_INFO_0 Info0 = NULL;
18 PUSER_MODALS_INFO_1 Info1 = NULL;
19 PUSER_MODALS_INFO_3 Info3 = NULL;
20 NT_PRODUCT_TYPE ProductType;
21 LPWSTR p;
22 LPWSTR endptr;
23 DWORD ParamErr;
24 ULONG value;
25 INT i;
26 BOOL Modified = FALSE;
27 #if 0
28 BOOL Domain = FALSE;
29 #endif
30 INT nPaddedLength = 58;
31 NET_API_STATUS Status;
32 INT result = 0;
33
34 for (i = 2; i < argc; i++)
35 {
36 if (_wcsicmp(argv[i], L"help") == 0)
37 {
38 /* Print short syntax help */
39 PrintResourceString(IDS_ACCOUNTS_SYNTAX);
40 return 0;
41 }
42
43 if (_wcsicmp(argv[i], L"/help") == 0)
44 {
45 /* Print full help text*/
46 PrintResourceString(IDS_ACCOUNTS_HELP);
47 return 0;
48 }
49
50 if (_wcsicmp(argv[i], L"/domain") == 0)
51 {
52 PrintResourceString(IDS_ERROR_OPTION_NOT_SUPPORTED, L"/DOMAIN");
53 #if 0
54 Domain = TRUE;
55 #endif
56 }
57 }
58
59 Status = NetUserModalsGet(NULL, 0, (LPBYTE*)&Info0);
60 if (Status != NERR_Success)
61 goto done;
62
63 for (i = 2; i < argc; i++)
64 {
65 if (_wcsnicmp(argv[i], L"/forcelogoff:", 13) == 0)
66 {
67 p = &argv[i][13];
68 if (wcsicmp(p, L"no"))
69 {
70 Info0->usrmod0_force_logoff = TIMEQ_FOREVER;
71 Modified = TRUE;
72 }
73 else
74 {
75 value = wcstoul(p, &endptr, 10);
76 if (*endptr != 0)
77 {
78 PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/FORCELOGOFF");
79 result = 1;
80 goto done;
81 }
82
83 Info0->usrmod0_force_logoff = value * 60;
84 Modified = TRUE;
85 }
86 }
87 else if (_wcsnicmp(argv[i], L"/minpwlen:", 10) == 0)
88 {
89 p = &argv[i][10];
90 value = wcstoul(p, &endptr, 10);
91 if (*endptr != 0)
92 {
93 PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/MINPWLEN");
94 result = 1;
95 goto done;
96 }
97
98 Info0->usrmod0_min_passwd_len = value;
99 Modified = TRUE;
100 }
101 else if (_wcsnicmp(argv[i], L"/maxpwage:", 10) == 0)
102 {
103 p = &argv[i][10];
104
105 if (wcsicmp(p, L"unlimited"))
106 {
107 Info0->usrmod0_max_passwd_age = ULONG_MAX;
108 Modified = TRUE;
109 }
110 else
111 {
112 value = wcstoul(p, &endptr, 10);
113 if (*endptr != 0)
114 {
115 PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/MAXPWLEN");
116 result = 1;
117 goto done;
118 }
119
120 Info0->usrmod0_max_passwd_age = value * 86400;
121 Modified = TRUE;
122 }
123 }
124 else if (_wcsnicmp(argv[i], L"/minpwage:", 10) == 0)
125 {
126 p = &argv[i][10];
127 value = wcstoul(p, &endptr, 10);
128 if (*endptr != 0)
129 {
130 PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/MINPWAGE");
131 result = 1;
132 goto done;
133 }
134
135 Info0->usrmod0_min_passwd_age = value * 86400;
136 Modified = TRUE;
137 }
138 else if (_wcsnicmp(argv[i], L"/uniquepw:", 10) == 0)
139 {
140 p = &argv[i][10];
141 value = wcstoul(p, &endptr, 10);
142 if (*endptr != 0)
143 {
144 PrintResourceString(IDS_ERROR_INVALID_OPTION_VALUE, L"/UNIQUEPW");
145 result = 1;
146 goto done;
147 }
148
149 Info0->usrmod0_password_hist_len = value;
150 Modified = TRUE;
151 }
152 }
153
154 if (Modified == TRUE)
155 {
156 Status = NetUserModalsSet(NULL, 0, (LPBYTE)Info0, &ParamErr);
157 if (Status != NERR_Success)
158 goto done;
159 }
160 else
161 {
162 Status = NetUserModalsGet(NULL, 1, (LPBYTE*)&Info1);
163 if (Status != NERR_Success)
164 goto done;
165
166 Status = NetUserModalsGet(NULL, 3, (LPBYTE*)&Info3);
167 if (Status != NERR_Success)
168 goto done;
169
170 RtlGetNtProductType(&ProductType);
171
172 PrintPaddedResourceString(IDS_ACCOUNTS_FORCE_LOGOFF, nPaddedLength);
173 if (Info0->usrmod0_force_logoff == TIMEQ_FOREVER)
174 PrintResourceString(IDS_GENERIC_NEVER);
175 else
176 PrintResourceString(IDS_ACCOUNTS_LOGOFF_SECONDS, Info0->usrmod0_force_logoff);
177 PrintToConsole(L"\n");
178
179 PrintPaddedResourceString(IDS_ACCOUNTS_MIN_PW_AGE, nPaddedLength);
180 PrintToConsole(L"%lu\n", Info0->usrmod0_min_passwd_age / 86400);
181
182 PrintPaddedResourceString(IDS_ACCOUNTS_MAX_PW_AGE, nPaddedLength);
183 PrintToConsole(L"%lu\n", Info0->usrmod0_max_passwd_age / 86400);
184
185 PrintPaddedResourceString(IDS_ACCOUNTS_MIN_PW_LENGTH, nPaddedLength);
186 PrintToConsole(L"%lu\n", Info0->usrmod0_min_passwd_len);
187
188 PrintPaddedResourceString(IDS_ACCOUNTS_PW_HIST_LENGTH, nPaddedLength);
189 if (Info0->usrmod0_password_hist_len == 0)
190 PrintResourceString(IDS_GENERIC_NONE);
191 else
192 PrintToConsole(L"%lu", Info0->usrmod0_password_hist_len);
193 PrintToConsole(L"\n");
194
195 PrintPaddedResourceString(IDS_ACCOUNTS_LOCKOUT_THRESHOLD, nPaddedLength);
196 if (Info3->usrmod3_lockout_threshold == 0)
197 PrintResourceString(IDS_GENERIC_NEVER);
198 else
199 PrintToConsole(L"%lu", Info3->usrmod3_lockout_threshold);
200 PrintToConsole(L"\n");
201
202 PrintPaddedResourceString(IDS_ACCOUNTS_LOCKOUT_DURATION, nPaddedLength);
203 PrintToConsole(L"%lu\n", Info3->usrmod3_lockout_duration / 60);
204
205 PrintPaddedResourceString(IDS_ACCOUNTS_LOCKOUT_WINDOW, nPaddedLength);
206 PrintToConsole(L"%lu\n", Info3->usrmod3_lockout_observation_window / 60);
207
208 PrintPaddedResourceString(IDS_ACCOUNTS_COMPUTER_ROLE, nPaddedLength);
209 if (Info1->usrmod1_role == UAS_ROLE_PRIMARY)
210 {
211 if (ProductType == NtProductLanManNt)
212 {
213 PrintResourceString(IDS_ACCOUNTS_PRIMARY_SERVER);
214 }
215 else if (ProductType == NtProductServer)
216 {
217 PrintResourceString(IDS_ACCOUNTS_STANDALONE_SERVER);
218 }
219 else
220 {
221 PrintResourceString(IDS_ACCOUNTS_WORKSTATION);
222 }
223 }
224 else
225 {
226 PrintResourceString(IDS_ACCOUNTS_BACKUP_SERVER);
227 }
228 PrintToConsole(L"\n");
229 }
230
231 done:
232 if (Info3 != NULL)
233 NetApiBufferFree(Info3);
234
235 if (Info1 != NULL)
236 NetApiBufferFree(Info1);
237
238 if (Info0 != NULL)
239 NetApiBufferFree(Info0);
240
241 return result;
242 }
243
244 /* EOF */