[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, perr;
22 DWORD ParamErr;
23 ULONG value;
24 INT i;
25 BOOL Modified = FALSE;
26 // BOOL Domain = FALSE;
27 NET_API_STATUS Status;
28
29 for (i = 3; i < argc; i++)
30 {
31 if (wcsicmp(argv[i], L"help") == 0)
32 {
33 /* Print short syntax help */
34 puts("NET ACCOUNTS [/FORCELOGOFF:{Minutes|NO}] [/MINPWLEN:Length]");
35 puts(" [/MAXPWAGE:{Days|UNLIMITED}] [/MINPWAGE:Days]");
36 puts(" [/UNIQUEPW:Count] [/DOMAIN]");
37 return 0;
38 }
39
40 if (wcsicmp(argv[i], L"/help") == 0)
41 {
42 /* FIXME: Print long help text*/
43 return 0;
44 }
45
46 /*
47 if (wcsicmp(argv[i], L"/domain") == 0)
48 {
49 Domain = TRUE;
50 }
51 */
52 }
53
54 Status = NetUserModalsGet(NULL, 0, (LPBYTE*)&Info0);
55 if (Status != NERR_Success)
56 goto done;
57
58 for (i = 3; i < argc; i++)
59 {
60 if (_wcsnicmp(argv[i], L"/forcelogoff:", 13) == 0)
61 {
62 p = &argv[i][13];
63 if (wcsicmp(p, L"no"))
64 {
65 Info0->usrmod0_force_logoff = TIMEQ_FOREVER;
66 Modified = TRUE;
67 }
68 else
69 {
70 value = wcstoul(p, &perr, 10);
71
72 Info0->usrmod0_force_logoff = value * 60;
73 Modified = TRUE;
74 }
75 }
76 else if (_wcsnicmp(argv[i], L"/minpwlen:", 10) == 0)
77 {
78 p = &argv[i][10];
79 value = wcstoul(p, &perr, 10);
80 Info0->usrmod0_min_passwd_len = value;
81 Modified = TRUE;
82 }
83 else if (_wcsnicmp(argv[i], L"/maxpwage:", 10) == 0)
84 {
85 p = &argv[i][10];
86
87 if (wcsicmp(p, L"unlimited"))
88 {
89 Info0->usrmod0_max_passwd_age = ULONG_MAX;
90 Modified = TRUE;
91 }
92 else
93 {
94 value = wcstoul(p, &perr, 10);
95
96 Info0->usrmod0_max_passwd_age = value * 86400;
97 Modified = TRUE;
98 }
99 }
100 else if (_wcsnicmp(argv[i], L"/minpwage:", 10) == 0)
101 {
102 p = &argv[i][10];
103 value = wcstoul(p, &perr, 10);
104
105 Info0->usrmod0_min_passwd_age = value * 86400;
106 Modified = TRUE;
107 }
108 else if (_wcsnicmp(argv[i], L"/uniquepw:", 10) == 0)
109 {
110 p = &argv[i][10];
111 value = wcstoul(p, &perr, 10);
112
113 Info0->usrmod0_password_hist_len = value;
114 Modified = TRUE;
115 }
116 }
117
118 if (Modified == TRUE)
119 {
120 Status = NetUserModalsSet(NULL, 0, (LPBYTE)Info0, &ParamErr);
121 if (Status != NERR_Success)
122 goto done;
123 }
124 else
125 {
126 Status = NetUserModalsGet(NULL, 1, (LPBYTE*)&Info1);
127 if (Status != NERR_Success)
128 goto done;
129
130 Status = NetUserModalsGet(NULL, 3, (LPBYTE*)&Info3);
131 if (Status != NERR_Success)
132 goto done;
133
134 RtlGetNtProductType(&ProductType);
135
136 printf("Force logoff after: ");
137 if (Info0->usrmod0_force_logoff == TIMEQ_FOREVER)
138 printf("Never\n");
139 else
140 printf("%lu seconds\n", Info0->usrmod0_force_logoff);
141
142 printf("Minimum password age (in days): %lu\n", Info0->usrmod0_min_passwd_age / 86400);
143 printf("Maximum password age (in days): %lu\n", Info0->usrmod0_max_passwd_age / 86400);
144 printf("Minimum password length: %lu\n", Info0->usrmod0_min_passwd_len);
145
146 printf("Password history length: ");
147 if (Info0->usrmod0_password_hist_len == 0)
148 printf("None\n");
149 else
150 printf("%lu\n", Info0->usrmod0_password_hist_len);
151
152 printf("Lockout threshold: %lu\n", Info3->usrmod3_lockout_threshold);
153 printf("Lockout duration (in minutes): %lu\n", Info3->usrmod3_lockout_duration / 60);
154 printf("Lockout observation window (in minutes): %lu\n", Info3->usrmod3_lockout_observation_window / 60);
155
156 printf("Computer role: ");
157
158 if (Info1->usrmod1_role == UAS_ROLE_PRIMARY)
159 {
160 if (ProductType == NtProductLanManNt)
161 {
162 printf("Primary server\n");
163 }
164 else if (ProductType == NtProductServer)
165 {
166 printf("Standalone server\n");
167 }
168 else
169 {
170 printf("Workstation\n");
171 }
172 }
173 else
174 {
175 printf("Backup server\n");
176 }
177 }
178
179 done:
180 if (Info3 != NULL)
181 NetApiBufferFree(Info3);
182
183 if (Info1 != NULL)
184 NetApiBufferFree(Info1);
185
186 if (Info0 != NULL)
187 NetApiBufferFree(Info0);
188
189 return 0;
190 }
191
192 /* EOF */