[NET][MC] Move generic strings from net.exe to netmsg.dll.
[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: base/applications/network/net/cmdAccounts.c
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 ConResPuts(StdOut, IDS_GENERIC_SYNTAX);
40 PrintNetMessage(MSG_ACCOUNTS_SYNTAX);
41 return 0;
42 }
43
44 if (_wcsicmp(argv[i], L"/help") == 0)
45 {
46 /* Print full help text*/
47 ConResPuts(StdOut, IDS_GENERIC_SYNTAX);
48 PrintNetMessage(MSG_ACCOUNTS_SYNTAX);
49 PrintNetMessage(MSG_ACCOUNTS_HELP);
50 return 0;
51 }
52
53 if (_wcsicmp(argv[i], L"/domain") == 0)
54 {
55 ConResPrintf(StdErr, IDS_ERROR_OPTION_NOT_SUPPORTED, L"/DOMAIN");
56 #if 0
57 Domain = TRUE;
58 #endif
59 }
60 }
61
62 Status = NetUserModalsGet(NULL, 0, (LPBYTE*)&Info0);
63 if (Status != NERR_Success)
64 goto done;
65
66 for (i = 2; i < argc; i++)
67 {
68 if (_wcsnicmp(argv[i], L"/forcelogoff:", 13) == 0)
69 {
70 p = &argv[i][13];
71 if (wcsicmp(p, L"no"))
72 {
73 Info0->usrmod0_force_logoff = TIMEQ_FOREVER;
74 Modified = TRUE;
75 }
76 else
77 {
78 value = wcstoul(p, &endptr, 10);
79 if (*endptr != 0)
80 {
81 ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/FORCELOGOFF");
82 result = 1;
83 goto done;
84 }
85
86 Info0->usrmod0_force_logoff = value * 60;
87 Modified = TRUE;
88 }
89 }
90 else if (_wcsnicmp(argv[i], L"/minpwlen:", 10) == 0)
91 {
92 p = &argv[i][10];
93 value = wcstoul(p, &endptr, 10);
94 if (*endptr != 0)
95 {
96 ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/MINPWLEN");
97 result = 1;
98 goto done;
99 }
100
101 Info0->usrmod0_min_passwd_len = value;
102 Modified = TRUE;
103 }
104 else if (_wcsnicmp(argv[i], L"/maxpwage:", 10) == 0)
105 {
106 p = &argv[i][10];
107
108 if (wcsicmp(p, L"unlimited"))
109 {
110 Info0->usrmod0_max_passwd_age = ULONG_MAX;
111 Modified = TRUE;
112 }
113 else
114 {
115 value = wcstoul(p, &endptr, 10);
116 if (*endptr != 0)
117 {
118 ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/MAXPWLEN");
119 result = 1;
120 goto done;
121 }
122
123 Info0->usrmod0_max_passwd_age = value * 86400;
124 Modified = TRUE;
125 }
126 }
127 else if (_wcsnicmp(argv[i], L"/minpwage:", 10) == 0)
128 {
129 p = &argv[i][10];
130 value = wcstoul(p, &endptr, 10);
131 if (*endptr != 0)
132 {
133 ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/MINPWAGE");
134 result = 1;
135 goto done;
136 }
137
138 Info0->usrmod0_min_passwd_age = value * 86400;
139 Modified = TRUE;
140 }
141 else if (_wcsnicmp(argv[i], L"/uniquepw:", 10) == 0)
142 {
143 p = &argv[i][10];
144 value = wcstoul(p, &endptr, 10);
145 if (*endptr != 0)
146 {
147 ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/UNIQUEPW");
148 result = 1;
149 goto done;
150 }
151
152 Info0->usrmod0_password_hist_len = value;
153 Modified = TRUE;
154 }
155 }
156
157 if (Modified == TRUE)
158 {
159 Status = NetUserModalsSet(NULL, 0, (LPBYTE)Info0, &ParamErr);
160 if (Status != NERR_Success)
161 goto done;
162 }
163 else
164 {
165 Status = NetUserModalsGet(NULL, 1, (LPBYTE*)&Info1);
166 if (Status != NERR_Success)
167 goto done;
168
169 Status = NetUserModalsGet(NULL, 3, (LPBYTE*)&Info3);
170 if (Status != NERR_Success)
171 goto done;
172
173 RtlGetNtProductType(&ProductType);
174
175 PrintPaddedResourceString(IDS_ACCOUNTS_FORCE_LOGOFF, nPaddedLength);
176 if (Info0->usrmod0_force_logoff == TIMEQ_FOREVER)
177 PrintMessageString(4305);
178 else
179 ConResPrintf(StdOut, IDS_ACCOUNTS_LOGOFF_SECONDS, Info0->usrmod0_force_logoff);
180 ConPuts(StdOut, L"\n");
181
182 PrintPaddedMessageString(4572, nPaddedLength);
183 ConPrintf(StdOut, L"%lu\n", Info0->usrmod0_min_passwd_age / 86400);
184
185 PrintPaddedMessageString(4573, nPaddedLength);
186 ConPrintf(StdOut, L"%lu\n", Info0->usrmod0_max_passwd_age / 86400);
187
188 PrintPaddedMessageString(4574, nPaddedLength);
189 ConPrintf(StdOut, L"%lu\n", Info0->usrmod0_min_passwd_len);
190
191 PrintPaddedMessageString(4575, nPaddedLength);
192 if (Info0->usrmod0_password_hist_len == 0)
193 PrintMessageString(4303);
194 else
195 ConPrintf(StdOut, L"%lu", Info0->usrmod0_password_hist_len);
196 ConPuts(StdOut, L"\n");
197
198 PrintPaddedMessageString(4578, nPaddedLength);
199 if (Info3->usrmod3_lockout_threshold == 0)
200 PrintMessageString(4305);
201 else
202 ConPrintf(StdOut, L"%lu", Info3->usrmod3_lockout_threshold);
203 ConPuts(StdOut, L"\n");
204
205 PrintPaddedMessageString(4579, nPaddedLength);
206 ConPrintf(StdOut, L"%lu\n", Info3->usrmod3_lockout_duration / 60);
207
208 PrintPaddedMessageString(4580, nPaddedLength);
209 ConPrintf(StdOut, L"%lu\n", Info3->usrmod3_lockout_observation_window / 60);
210
211 PrintPaddedMessageString(4576, nPaddedLength);
212 if (Info1->usrmod1_role == UAS_ROLE_PRIMARY)
213 {
214 if (ProductType == NtProductLanManNt)
215 {
216 ConResPuts(StdOut, IDS_ACCOUNTS_PRIMARY_SERVER);
217 }
218 else if (ProductType == NtProductServer)
219 {
220 ConResPuts(StdOut, IDS_ACCOUNTS_STANDALONE_SERVER);
221 }
222 else
223 {
224 ConResPuts(StdOut, IDS_ACCOUNTS_WORKSTATION);
225 }
226 }
227 else
228 {
229 ConResPuts(StdOut, IDS_ACCOUNTS_BACKUP_SERVER);
230 }
231 ConPuts(StdOut, L"\n");
232 }
233
234 done:
235 if (Info3 != NULL)
236 NetApiBufferFree(Info3);
237
238 if (Info1 != NULL)
239 NetApiBufferFree(Info1);
240
241 if (Info0 != NULL)
242 NetApiBufferFree(Info0);
243
244 return result;
245 }
246
247 /* EOF */