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