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