ReactOS  0.4.13-dev-99-g7e18b6d
cmdAccounts.c
Go to the documentation of this file.
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
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;
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  PrintMessageString(4381);
40  ConPuts(StdOut, L"\n");
41  PrintNetMessage(MSG_ACCOUNTS_SYNTAX);
42  return 0;
43  }
44 
45  if (_wcsicmp(argv[i], L"/help") == 0)
46  {
47  /* Print full help text*/
48  PrintMessageString(4381);
49  ConPuts(StdOut, L"\n");
50  PrintNetMessage(MSG_ACCOUNTS_SYNTAX);
51  PrintNetMessage(MSG_ACCOUNTS_HELP);
52  return 0;
53  }
54 
55  if (_wcsicmp(argv[i], L"/domain") == 0)
56  {
57  ConPuts(StdErr, L"The /DOMAIN option is not supported yet.\n");
58 #if 0
59  Domain = TRUE;
60 #endif
61  }
62  }
63 
64  Status = NetUserModalsGet(NULL, 0, (LPBYTE*)&Info0);
65  if (Status != NERR_Success)
66  goto done;
67 
68  for (i = 2; i < argc; i++)
69  {
70  if (_wcsnicmp(argv[i], L"/forcelogoff:", 13) == 0)
71  {
72  p = &argv[i][13];
73  if (wcsicmp(p, L"no") == 0)
74  {
75  Info0->usrmod0_force_logoff = TIMEQ_FOREVER;
76  Modified = TRUE;
77  }
78  else
79  {
80  value = wcstoul(p, &endptr, 10);
81  if (*endptr != 0)
82  {
83  PrintMessageStringV(3952, L"/FORCELOGOFF");
84  result = 1;
85  goto done;
86  }
87 
88  Info0->usrmod0_force_logoff = value * 60;
89  Modified = TRUE;
90  }
91  }
92  else if (_wcsnicmp(argv[i], L"/minpwlen:", 10) == 0)
93  {
94  p = &argv[i][10];
95  value = wcstoul(p, &endptr, 10);
96  if (*endptr != 0)
97  {
98  PrintMessageStringV(3952, L"/MINPWLEN");
99  result = 1;
100  goto done;
101  }
102 
103  Info0->usrmod0_min_passwd_len = value;
104  Modified = TRUE;
105  }
106  else if (_wcsnicmp(argv[i], L"/maxpwage:", 10) == 0)
107  {
108  p = &argv[i][10];
109 
110  if (wcsicmp(p, L"unlimited"))
111  {
112  Info0->usrmod0_max_passwd_age = ULONG_MAX;
113  Modified = TRUE;
114  }
115  else
116  {
117  value = wcstoul(p, &endptr, 10);
118  if (*endptr != 0)
119  {
120  PrintMessageStringV(3952, L"/MAXPWLEN");
121  result = 1;
122  goto done;
123  }
124 
125  Info0->usrmod0_max_passwd_age = value * 86400;
126  Modified = TRUE;
127  }
128  }
129  else if (_wcsnicmp(argv[i], L"/minpwage:", 10) == 0)
130  {
131  p = &argv[i][10];
132  value = wcstoul(p, &endptr, 10);
133  if (*endptr != 0)
134  {
135  PrintMessageStringV(3952, L"/MINPWAGE");
136  result = 1;
137  goto done;
138  }
139 
140  Info0->usrmod0_min_passwd_age = value * 86400;
141  Modified = TRUE;
142  }
143  else if (_wcsnicmp(argv[i], L"/uniquepw:", 10) == 0)
144  {
145  p = &argv[i][10];
146  value = wcstoul(p, &endptr, 10);
147  if (*endptr != 0)
148  {
149  PrintMessageStringV(3952, L"/UNIQUEPW");
150  result = 1;
151  goto done;
152  }
153 
154  Info0->usrmod0_password_hist_len = value;
155  Modified = TRUE;
156  }
157  }
158 
159  if (Modified == TRUE)
160  {
161  Status = NetUserModalsSet(NULL, 0, (LPBYTE)Info0, &ParamErr);
162  if (Status != NERR_Success)
163  goto done;
164  }
165  else
166  {
167  Status = NetUserModalsGet(NULL, 1, (LPBYTE*)&Info1);
168  if (Status != NERR_Success)
169  goto done;
170 
171  Status = NetUserModalsGet(NULL, 3, (LPBYTE*)&Info3);
172  if (Status != NERR_Success)
173  goto done;
174 
175  RtlGetNtProductType(&ProductType);
176 
178  if (Info0->usrmod0_force_logoff == TIMEQ_FOREVER)
179  PrintMessageString(4305);
180  else
181  ConResPrintf(StdOut, IDS_ACCOUNTS_LOGOFF_SECONDS, Info0->usrmod0_force_logoff);
182  ConPuts(StdOut, L"\n");
183 
184  PrintPaddedMessageString(4572, nPaddedLength);
185  ConPrintf(StdOut, L"%lu\n", Info0->usrmod0_min_passwd_age / 86400);
186 
187  PrintPaddedMessageString(4573, nPaddedLength);
188  ConPrintf(StdOut, L"%lu\n", Info0->usrmod0_max_passwd_age / 86400);
189 
190  PrintPaddedMessageString(4574, nPaddedLength);
191  ConPrintf(StdOut, L"%lu\n", Info0->usrmod0_min_passwd_len);
192 
193  PrintPaddedMessageString(4575, nPaddedLength);
194  if (Info0->usrmod0_password_hist_len == 0)
195  PrintMessageString(4303);
196  else
197  ConPrintf(StdOut, L"%lu", Info0->usrmod0_password_hist_len);
198  ConPuts(StdOut, L"\n");
199 
200  PrintPaddedMessageString(4578, nPaddedLength);
201  if (Info3->usrmod3_lockout_threshold == 0)
202  PrintMessageString(4305);
203  else
204  ConPrintf(StdOut, L"%lu", Info3->usrmod3_lockout_threshold);
205  ConPuts(StdOut, L"\n");
206 
207  PrintPaddedMessageString(4579, nPaddedLength);
208  ConPrintf(StdOut, L"%lu\n", Info3->usrmod3_lockout_duration / 60);
209 
210  PrintPaddedMessageString(4580, nPaddedLength);
211  ConPrintf(StdOut, L"%lu\n", Info3->usrmod3_lockout_observation_window / 60);
212 
213  PrintPaddedMessageString(4576, nPaddedLength);
214  if (Info1->usrmod1_role == UAS_ROLE_PRIMARY)
215  {
216  if (ProductType == NtProductLanManNt)
217  {
219  }
220  else if (ProductType == NtProductServer)
221  {
223  }
224  else
225  {
227  }
228  }
229  else
230  {
232  }
233  ConPuts(StdOut, L"\n");
234  }
235 
236 done:
237  if (Info3 != NULL)
238  NetApiBufferFree(Info3);
239 
240  if (Info1 != NULL)
241  NetApiBufferFree(Info1);
242 
243  if (Info0 != NULL)
244  NetApiBufferFree(Info0);
245 
246  return result;
247 }
248 
249 /* EOF */
static int argc
Definition: ServiceArgs.c:12
#define IDS_ACCOUNTS_LOGOFF_SECONDS
Definition: resource.h:4
#define IDS_ACCOUNTS_PRIMARY_SERVER
Definition: resource.h:5
#define TRUE
Definition: types.h:120
VOID PrintMessageStringV(DWORD dwMessage,...)
Definition: main.c:82
#define IDS_ACCOUNTS_WORKSTATION
Definition: resource.h:8
_Check_return_ _CRTIMP int __cdecl _wcsnicmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
#define IDS_ACCOUNTS_STANDALONE_SERVER
Definition: resource.h:7
VOID PrintNetMessage(DWORD dwMessage)
Definition: main.c:228
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define argv
Definition: mplay32.c:18
int32_t INT
Definition: typedefs.h:56
#define NERR_Success
Definition: lmerr.h:5
#define IDS_ACCOUNTS_BACKUP_SERVER
Definition: resource.h:6
BOOLEAN NTAPI RtlGetNtProductType(PNT_PRODUCT_TYPE ProductType)
Definition: version.c:96
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned char * LPBYTE
Definition: typedefs.h:52
unsigned int BOOL
Definition: ntddk_ex.h:94
NET_API_STATUS WINAPI NetUserModalsGet(LPCWSTR servername, DWORD level, LPBYTE *bufptr)
Definition: user.c:3676
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
smooth NULL
Definition: ftsmooth.c:416
#define IDS_ACCOUNTS_FORCE_LOGOFF
Definition: resource.h:3
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
__wchar_t WCHAR
Definition: xmlstorage.h:180
NET_API_STATUS WINAPI NetUserModalsSet(IN LPCWSTR servername, IN DWORD level, IN LPBYTE buf, OUT LPDWORD parm_err)
Definition: user.c:3960
#define UAS_ROLE_PRIMARY
Definition: lmaccess.h:53
INT cmdAccounts(INT argc, WCHAR **argv)
Definition: cmdAccounts.c:13
unsigned long DWORD
Definition: ntddk_ex.h:95
#define StdErr
Definition: stream.h:77
INT ConResPuts(IN PCON_STREAM Stream, IN UINT uID)
Definition: outstream.c:610
static const WCHAR L[]
Definition: oid.c:1250
GLsizei const GLfloat * value
Definition: glext.h:6069
#define wcsicmp
Definition: string.h:1152
Status
Definition: gdiplustypes.h:24
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
VOID PrintPaddedMessageString(DWORD dwMessage, INT nPaddedLength)
Definition: main.c:132
VOID PrintPaddedResourceString(UINT uID, INT nPaddedLength)
Definition: main.c:53
VOID PrintMessageString(DWORD dwMessage)
Definition: main.c:109
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
#define TIMEQ_FOREVER
Definition: lmaccess.h:110
#define StdOut
Definition: stream.h:76
enum _NT_PRODUCT_TYPE NT_PRODUCT_TYPE
unsigned int ULONG
Definition: retypes.h:1
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
GLuint64EXT * result
Definition: glext.h:11304
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define ULONG_MAX
Definition: limits.h:44