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             ConResPuts(StdOut, IDS_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             ConResPuts(StdOut, IDS_ACCOUNTS_SYNTAX);
49             ConResPuts(StdOut, IDS_ACCOUNTS_HELP_1);
50             ConResPuts(StdOut, IDS_ACCOUNTS_HELP_2);
51             ConResPuts(StdOut, IDS_ACCOUNTS_HELP_3);
52             ConResPuts(StdOut, IDS_ACCOUNTS_HELP_4);
53             ConResPuts(StdOut, IDS_ACCOUNTS_HELP_5);
54             ConResPuts(StdOut, IDS_ACCOUNTS_HELP_6);
55             ConResPuts(StdOut, IDS_ACCOUNTS_HELP_7);
56             ConResPuts(StdOut, IDS_ACCOUNTS_HELP_8);
57             ConResPuts(StdOut, IDS_ACCOUNTS_HELP_9);
58             ConResPuts(StdOut, IDS_ACCOUNTS_HELP_10);
59             ConResPuts(StdOut, IDS_GENERIC_PAGE);
60             return 0;
61         }
62 
63         if (_wcsicmp(argv[i], L"/domain") == 0)
64         {
65             ConResPrintf(StdErr, IDS_ERROR_OPTION_NOT_SUPPORTED, L"/DOMAIN");
66 #if 0
67             Domain = TRUE;
68 #endif
69         }
70     }
71 
72     Status = NetUserModalsGet(NULL, 0, (LPBYTE*)&Info0);
73     if (Status != NERR_Success)
74         goto done;
75 
76     for (i = 2; i < argc; i++)
77     {
78         if (_wcsnicmp(argv[i], L"/forcelogoff:", 13) == 0)
79         {
80             p = &argv[i][13];
81             if (wcsicmp(p, L"no"))
82             {
83                 Info0->usrmod0_force_logoff = TIMEQ_FOREVER;
84                 Modified = TRUE;
85             }
86             else
87             {
88                 value = wcstoul(p, &endptr, 10);
89                 if (*endptr != 0)
90                 {
91                     ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/FORCELOGOFF");
92                     result = 1;
93                     goto done;
94                 }
95 
96                 Info0->usrmod0_force_logoff = value * 60;
97                 Modified = TRUE;
98             }
99         }
100         else if (_wcsnicmp(argv[i], L"/minpwlen:", 10) == 0)
101         {
102             p = &argv[i][10];
103             value = wcstoul(p, &endptr, 10);
104             if (*endptr != 0)
105             {
106                 ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/MINPWLEN");
107                 result = 1;
108                 goto done;
109             }
110 
111             Info0->usrmod0_min_passwd_len = value;
112             Modified = TRUE;
113         }
114         else if (_wcsnicmp(argv[i], L"/maxpwage:", 10) == 0)
115         {
116             p = &argv[i][10];
117 
118             if (wcsicmp(p, L"unlimited"))
119             {
120                 Info0->usrmod0_max_passwd_age = ULONG_MAX;
121                 Modified = TRUE;
122             }
123             else
124             {
125                 value = wcstoul(p, &endptr, 10);
126                 if (*endptr != 0)
127                 {
128                     ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/MAXPWLEN");
129                     result = 1;
130                     goto done;
131                 }
132 
133                 Info0->usrmod0_max_passwd_age = value * 86400;
134                 Modified = TRUE;
135             }
136         }
137         else if (_wcsnicmp(argv[i], L"/minpwage:", 10) == 0)
138         {
139             p = &argv[i][10];
140             value = wcstoul(p, &endptr, 10);
141             if (*endptr != 0)
142             {
143                 ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/MINPWAGE");
144                 result = 1;
145                 goto done;
146             }
147 
148             Info0->usrmod0_min_passwd_age = value * 86400;
149             Modified = TRUE;
150         }
151         else if (_wcsnicmp(argv[i], L"/uniquepw:", 10) == 0)
152         {
153             p = &argv[i][10];
154             value = wcstoul(p, &endptr, 10);
155             if (*endptr != 0)
156             {
157                 ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/UNIQUEPW");
158                 result = 1;
159                 goto done;
160             }
161 
162             Info0->usrmod0_password_hist_len = value;
163             Modified = TRUE;
164         }
165     }
166 
167     if (Modified != FALSE)
168     {
169         Status = NetUserModalsSet(NULL, 0, (LPBYTE)Info0, &ParamErr);
170         if (Status != NERR_Success)
171             goto done;
172     }
173     else
174     {
175         Status = NetUserModalsGet(NULL, 1, (LPBYTE*)&Info1);
176         if (Status != NERR_Success)
177             goto done;
178 
179         Status = NetUserModalsGet(NULL, 3, (LPBYTE*)&Info3);
180         if (Status != NERR_Success)
181             goto done;
182 
183         RtlGetNtProductType(&ProductType);
184 
185         PrintPaddedResourceString(IDS_ACCOUNTS_FORCE_LOGOFF, nPaddedLength);
186         if (Info0->usrmod0_force_logoff == TIMEQ_FOREVER)
187             ConResPuts(StdOut, IDS_GENERIC_NEVER);
188         else
189             ConResPrintf(StdOut, IDS_ACCOUNTS_LOGOFF_SECONDS, Info0->usrmod0_force_logoff);
190         ConPuts(StdOut, L"\n");
191 
192         PrintPaddedResourceString(IDS_ACCOUNTS_MIN_PW_AGE, nPaddedLength);
193         ConPrintf(StdOut, L"%lu\n", Info0->usrmod0_min_passwd_age / 86400);
194 
195         PrintPaddedResourceString(IDS_ACCOUNTS_MAX_PW_AGE, nPaddedLength);
196         ConPrintf(StdOut, L"%lu\n", Info0->usrmod0_max_passwd_age / 86400);
197 
198         PrintPaddedResourceString(IDS_ACCOUNTS_MIN_PW_LENGTH, nPaddedLength);
199         ConPrintf(StdOut, L"%lu\n", Info0->usrmod0_min_passwd_len);
200 
201         PrintPaddedResourceString(IDS_ACCOUNTS_PW_HIST_LENGTH, nPaddedLength);
202         if (Info0->usrmod0_password_hist_len == 0)
203             ConResPuts(StdOut, IDS_GENERIC_NONE);
204         else
205             ConPrintf(StdOut, L"%lu", Info0->usrmod0_password_hist_len);
206         ConPuts(StdOut, L"\n");
207 
208         PrintPaddedResourceString(IDS_ACCOUNTS_LOCKOUT_THRESHOLD, nPaddedLength);
209         if (Info3->usrmod3_lockout_threshold == 0)
210             ConResPuts(StdOut, IDS_GENERIC_NEVER);
211         else
212             ConPrintf(StdOut, L"%lu", Info3->usrmod3_lockout_threshold);
213         ConPuts(StdOut, L"\n");
214 
215         PrintPaddedResourceString(IDS_ACCOUNTS_LOCKOUT_DURATION, nPaddedLength);
216         ConPrintf(StdOut, L"%lu\n", Info3->usrmod3_lockout_duration / 60);
217 
218         PrintPaddedResourceString(IDS_ACCOUNTS_LOCKOUT_WINDOW, nPaddedLength);
219         ConPrintf(StdOut, L"%lu\n", Info3->usrmod3_lockout_observation_window / 60);
220 
221         PrintPaddedResourceString(IDS_ACCOUNTS_COMPUTER_ROLE, nPaddedLength);
222         if (Info1->usrmod1_role == UAS_ROLE_PRIMARY)
223         {
224             if (ProductType == NtProductLanManNt)
225             {
226                 ConResPuts(StdOut, IDS_ACCOUNTS_PRIMARY_SERVER);
227             }
228             else if (ProductType == NtProductServer)
229             {
230                 ConResPuts(StdOut, IDS_ACCOUNTS_STANDALONE_SERVER);
231             }
232             else
233             {
234                 ConResPuts(StdOut, IDS_ACCOUNTS_WORKSTATION);
235             }
236         }
237         else
238         {
239             ConResPuts(StdOut, IDS_ACCOUNTS_BACKUP_SERVER);
240         }
241         ConPuts(StdOut, L"\n");
242     }
243 
244 done:
245     if (Info3 != NULL)
246         NetApiBufferFree(Info3);
247 
248     if (Info1 != NULL)
249         NetApiBufferFree(Info1);
250 
251     if (Info0 != NULL)
252         NetApiBufferFree(Info0);
253 
254     return result;
255 }
256 
257 /* EOF */
258