456ac4c791e3dab9f225586fb038b7e1b914a1a0
[reactos.git] / reactos / 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 // BOOL Domain = FALSE;
28 NET_API_STATUS Status;
29 INT result = 0;
30
31 for (i = 2; i < argc; i++)
32 {
33 if (_wcsicmp(argv[i], L"help") == 0)
34 {
35 /* Print short syntax help */
36 PrintResourceString(IDS_ACCOUNTS_SYNTAX);
37 return 0;
38 }
39
40 if (_wcsicmp(argv[i], L"/help") == 0)
41 {
42 /* Print full help text*/
43 PrintResourceString(IDS_ACCOUNTS_HELP);
44 return 0;
45 }
46
47 /*
48 if (_wcsicmp(argv[i], L"/domain") == 0)
49 {
50 Domain = TRUE;
51 }
52 */
53 }
54
55 Status = NetUserModalsGet(NULL, 0, (LPBYTE*)&Info0);
56 if (Status != NERR_Success)
57 goto done;
58
59 for (i = 2; i < argc; i++)
60 {
61 if (_wcsnicmp(argv[i], L"/forcelogoff:", 13) == 0)
62 {
63 p = &argv[i][13];
64 if (wcsicmp(p, L"no"))
65 {
66 Info0->usrmod0_force_logoff = TIMEQ_FOREVER;
67 Modified = TRUE;
68 }
69 else
70 {
71 value = wcstoul(p, &endptr, 10);
72 if (*endptr != 0)
73 {
74 printf("You entered an invalid value for the /FORCELOGOFF option.\n");
75 result = 1;
76 goto done;
77 }
78
79 Info0->usrmod0_force_logoff = value * 60;
80 Modified = TRUE;
81 }
82 }
83 else if (_wcsnicmp(argv[i], L"/minpwlen:", 10) == 0)
84 {
85 p = &argv[i][10];
86 value = wcstoul(p, &endptr, 10);
87 if (*endptr != 0)
88 {
89 printf("You entered an invalid value for the /MINPWLEN option.\n");
90 result = 1;
91 goto done;
92 }
93
94 Info0->usrmod0_min_passwd_len = value;
95 Modified = TRUE;
96 }
97 else if (_wcsnicmp(argv[i], L"/maxpwage:", 10) == 0)
98 {
99 p = &argv[i][10];
100
101 if (wcsicmp(p, L"unlimited"))
102 {
103 Info0->usrmod0_max_passwd_age = ULONG_MAX;
104 Modified = TRUE;
105 }
106 else
107 {
108 value = wcstoul(p, &endptr, 10);
109 if (*endptr != 0)
110 {
111 printf("You entered an invalid value for the /MAXPWAGE option.\n");
112 result = 1;
113 goto done;
114 }
115
116 Info0->usrmod0_max_passwd_age = value * 86400;
117 Modified = TRUE;
118 }
119 }
120 else if (_wcsnicmp(argv[i], L"/minpwage:", 10) == 0)
121 {
122 p = &argv[i][10];
123 value = wcstoul(p, &endptr, 10);
124 if (*endptr != 0)
125 {
126 printf("You entered an invalid value for the /MINPWAGE option.\n");
127 result = 1;
128 goto done;
129 }
130
131 Info0->usrmod0_min_passwd_age = value * 86400;
132 Modified = TRUE;
133 }
134 else if (_wcsnicmp(argv[i], L"/uniquepw:", 10) == 0)
135 {
136 p = &argv[i][10];
137 value = wcstoul(p, &endptr, 10);
138 if (*endptr != 0)
139 {
140 printf("You entered an invalid value for the /UNIQUEPW option.\n");
141 result = 1;
142 goto done;
143 }
144
145 Info0->usrmod0_password_hist_len = value;
146 Modified = TRUE;
147 }
148 }
149
150 if (Modified == TRUE)
151 {
152 Status = NetUserModalsSet(NULL, 0, (LPBYTE)Info0, &ParamErr);
153 if (Status != NERR_Success)
154 goto done;
155 }
156 else
157 {
158 Status = NetUserModalsGet(NULL, 1, (LPBYTE*)&Info1);
159 if (Status != NERR_Success)
160 goto done;
161
162 Status = NetUserModalsGet(NULL, 3, (LPBYTE*)&Info3);
163 if (Status != NERR_Success)
164 goto done;
165
166 RtlGetNtProductType(&ProductType);
167
168 printf("Force logoff after: ");
169 if (Info0->usrmod0_force_logoff == TIMEQ_FOREVER)
170 printf("Never\n");
171 else
172 printf("%lu seconds\n", Info0->usrmod0_force_logoff);
173
174 printf("Minimum password age (in days): %lu\n", Info0->usrmod0_min_passwd_age / 86400);
175 printf("Maximum password age (in days): %lu\n", Info0->usrmod0_max_passwd_age / 86400);
176 printf("Minimum password length: %lu\n", Info0->usrmod0_min_passwd_len);
177
178 printf("Password history length: ");
179 if (Info0->usrmod0_password_hist_len == 0)
180 printf("None\n");
181 else
182 printf("%lu\n", Info0->usrmod0_password_hist_len);
183
184 printf("Lockout threshold: ");
185 if (Info3->usrmod3_lockout_threshold == 0)
186 printf("Never\n");
187 else
188 printf("%lu\n", Info3->usrmod3_lockout_threshold);
189
190 printf("Lockout duration (in minutes): %lu\n", Info3->usrmod3_lockout_duration / 60);
191 printf("Lockout observation window (in minutes): %lu\n", Info3->usrmod3_lockout_observation_window / 60);
192
193 printf("Computer role: ");
194
195 if (Info1->usrmod1_role == UAS_ROLE_PRIMARY)
196 {
197 if (ProductType == NtProductLanManNt)
198 {
199 printf("Primary server\n");
200 }
201 else if (ProductType == NtProductServer)
202 {
203 printf("Standalone server\n");
204 }
205 else
206 {
207 printf("Workstation\n");
208 }
209 }
210 else
211 {
212 printf("Backup server\n");
213 }
214 }
215
216 done:
217 if (Info3 != NULL)
218 NetApiBufferFree(Info3);
219
220 if (Info1 != NULL)
221 NetApiBufferFree(Info1);
222
223 if (Info0 != NULL)
224 NetApiBufferFree(Info0);
225
226 return result;
227 }
228
229 /* EOF */