ReactOS  0.4.12-dev-18-gf469aca
cmdConfig.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/cmdConfig.c
5  * PROGRAMMERS: Eric Kohl <eric.kohl@reactos.org>
6  */
7 
8 #include "net.h"
9 
10 static
11 INT
13  PSERVER_INFO_102 ServerInfo)
14 {
15  PSERVER_TRANSPORT_INFO_0 TransportInfo = NULL;
16  DWORD dwRead, dwTotal, i;
17  INT nPaddedLength = 38;
19 
20  Status = NetServerTransportEnum(NULL, 0, (PBYTE*)&TransportInfo,
22  &dwRead,
23  &dwTotal,
24  NULL);
25  if (Status != NERR_Success)
26  goto done;
27 
29  ConPrintf(StdOut, L"\\\\%s\n", ServerInfo->sv102_name);
30 
32  ConPrintf(StdOut, L"%s\n\n", ServerInfo->sv102_comment);
33 
35  ConPrintf(StdOut, L"%lu.%lu\n",
36  ServerInfo->sv102_version_major,
37  ServerInfo->sv102_version_minor);
38 
40  ConPuts(StdOut, L"\n");
41  for (i = 0; i < dwRead; i++)
42  {
43  ConPrintf(StdOut, L" %s (%s)\n",
44  &TransportInfo[i].svti0_transportname[8],
45  TransportInfo[i].svti0_networkaddress);
46  }
47  ConPuts(StdOut, L"\n");
48 
51  ConPuts(StdOut, L"\n");
52 
54  ConPrintf(StdOut, L"%lu\n", ServerInfo->sv102_users);
55 
57  ConPuts(StdOut, L"...\n\n");
58 
60  if (ServerInfo->sv102_disc == SV_NODISC)
62  else
63  ConPrintf(StdOut, L"%lu\n", ServerInfo->sv102_disc);
64 
65 done:
66  if (TransportInfo != NULL)
67  NetApiBufferFree(TransportInfo);
68 
69  return 0;
70 }
71 
72 
73 static
74 INT
76 {
77  PWKSTA_INFO_100 WorkstationInfo = NULL;
78  PWKSTA_USER_INFO_1 UserInfo = NULL;
79  PWKSTA_TRANSPORT_INFO_0 TransportInfo = NULL;
80  DWORD dwRead = 0, dwTotal = 0, i;
81  INT nPaddedLength = 38;
83 
84  Status = NetWkstaGetInfo(NULL, 100, (PBYTE*)&WorkstationInfo);
85  if (Status != NERR_Success)
86  goto done;
87 
88  Status = NetWkstaUserGetInfo(NULL, 1, (PBYTE*)&UserInfo);
89  if (Status != NERR_Success)
90  goto done;
91 
92  Status = NetWkstaTransportEnum(NULL,
93  0,
94  (PBYTE*)&TransportInfo,
96  &dwRead,
97  &dwTotal,
98  NULL);
99  if (Status != NERR_Success)
100  goto done;
101 
103  ConPrintf(StdOut, L"\\\\%s\n", WorkstationInfo->wki100_computername);
104 
106  ConPuts(StdOut, L"...\n");
107 
109  ConPrintf(StdOut, L"%s\n", UserInfo->wkui1_username);
110 
111  ConPuts(StdOut, L"\n");
112 
114  ConPuts(StdOut, L"\n");
115  for (i = 0; i < dwRead; i++)
116  {
117  ConPrintf(StdOut, L" %s (%s)\n",
118  &TransportInfo[i].wkti0_transport_name[8],
119  TransportInfo[i].wkti0_transport_address);
120  }
121  ConPuts(StdOut, L"\n");
122 
124  ConPrintf(StdOut, L"%lu.%lu\n",
125  WorkstationInfo->wki100_ver_major,
126  WorkstationInfo->wki100_ver_minor);
127 
128  ConPuts(StdOut, L"\n");
129 
131  ConPrintf(StdOut, L"%s\n", WorkstationInfo->wki100_langroup);
132 
134  ConPrintf(StdOut, L"%s\n", UserInfo->wkui1_logon_domain);
135 
136 done:
137  if (TransportInfo != NULL)
138  NetApiBufferFree(TransportInfo);
139 
140  if (UserInfo != NULL)
141  NetApiBufferFree(UserInfo);
142 
143  if (WorkstationInfo != NULL)
144  NetApiBufferFree(WorkstationInfo);
145 
146  return 0;
147 }
148 
149 
150 INT
152  INT argc,
153  WCHAR **argv)
154 {
155  INT i, result = 0;
156  BOOL bServer = FALSE;
157  BOOL bWorkstation = FALSE;
158  PWSTR p, endptr;
159  BOOL bModify = FALSE;
160  LONG lValue;
161  PSERVER_INFO_102 ServerInfo = NULL;
163 
164  for (i = 2; i < argc; i++)
165  {
166  if (_wcsicmp(argv[i], L"server") == 0)
167  {
168  if (bWorkstation == FALSE)
169  bServer = TRUE;
170  continue;
171  }
172 
173  if (_wcsicmp(argv[i], L"workstation") == 0)
174  {
175  if (bServer == FALSE)
176  bWorkstation = TRUE;
177  continue;
178  }
179 
180  if (_wcsicmp(argv[i], L"help") == 0)
181  {
182  /* Print short syntax help */
183  if (bServer == TRUE)
184  {
187  }
188  else
189  {
192  }
193  return 0;
194  }
195 
196  if (_wcsicmp(argv[i], L"/help") == 0)
197  {
198  /* Print full help text*/
199  if (bServer == TRUE)
200  {
209  }
210  else
211  {
216  }
217  return 0;
218  }
219  }
220 
221  if (bServer)
222  {
223  Status = NetServerGetInfo(NULL, 102, (PBYTE*)&ServerInfo);
224  if (Status != NERR_Success)
225  goto done;
226 
227  for (i = 2; i < argc; i++)
228  {
229  if (argv[i][0] != L'/')
230  continue;
231 
232  if (_wcsnicmp(argv[i], L"/autodisconnect:", 16) == 0)
233  {
234  p = &argv[i][16];
235  lValue = wcstol(p, &endptr, 10);
236  if (*endptr != 0)
237  {
239  result = 1;
240  goto done;
241  }
242 
243  if (lValue < -1 || lValue > 65535)
244  {
246  result = 1;
247  goto done;
248  }
249 
250  ServerInfo->sv102_disc = lValue;
251  bModify = TRUE;
252  }
253  else if (_wcsnicmp(argv[i], L"/srvcomment:", 12) == 0)
254  {
255  ServerInfo->sv102_comment = &argv[i][12];
256  bModify = TRUE;
257  }
258  else if (_wcsnicmp(argv[i], L"/hidden:", 8) == 0)
259  {
260  p = &argv[i][8];
261  if (_wcsicmp(p, L"yes") != 0 && _wcsicmp(p, L"no") != 0)
262  {
264  result = 1;
265  goto done;
266  }
267 
268  ServerInfo->sv102_hidden = (_wcsicmp(p, L"yes") == 0) ? TRUE : FALSE;
269  bModify = TRUE;
270  }
271  else
272  {
275  result = 1;
276  goto done;
277  }
278  }
279 
280  if (bModify)
281  {
282  Status = NetServerSetInfo(NULL, 102, (PBYTE)&ServerInfo, NULL);
283  if (Status != NERR_Success)
284  result = 1;
285  }
286  else
287  {
288  result = DisplayServerConfig(ServerInfo);
289  }
290  }
291  else if (bWorkstation)
292  {
293  result = DisplayWorkstationConfig();
294  }
295  else
296  {
298  }
299 
300 done:
301  if (ServerInfo != NULL)
302  NetApiBufferFree(ServerInfo);
303 
304  if (result == 0)
306 
307  return result;
308 }
#define IDS_GENERIC_NO
Definition: resource.h:196
DWORD sv102_version_major
Definition: lmserver.h:28
#define MAX_PREFERRED_LENGTH
Definition: lmcons.h:48
static int argc
Definition: ServiceArgs.c:12
NET_API_STATUS WINAPI NetServerSetInfo(_In_ LPWSTR servername, _In_ DWORD level, _In_ LPBYTE buf, _Out_ LPDWORD parm_err)
Definition: srvsvc.c:399
LPWSTR sv102_name
Definition: lmserver.h:27
#define TRUE
Definition: types.h:120
#define SV_HIDDEN
Definition: lmserver.h:458
#define IDS_CONFIG_SERVER_ACTIVE
Definition: resource.h:106
#define IDS_CONFIG_WORKSTATION_NAME
Definition: resource.h:111
#define IDS_CONFIG_SERVER_FILES
Definition: resource.h:109
__wchar_t WCHAR
Definition: xmlstorage.h:180
uint16_t * PWSTR
Definition: typedefs.h:54
_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)
LPWSTR sv102_comment
Definition: lmserver.h:31
#define IDS_ERROR_INVALID_OPTION_VALUE
Definition: resource.h:206
#define IDS_CONFIG_SERVER_USERS
Definition: resource.h:108
#define IDS_CONFIG_SYNTAX
Definition: resource.h:17
#define IDS_CONFIG_WORKSTATION_USERNAME
Definition: resource.h:113
_Check_return_ long __cdecl wcstol(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
static INT DisplayServerConfig(PSERVER_INFO_102 ServerInfo)
Definition: cmdConfig.c:12
#define IDS_CONFIG_SERVER_HELP_5
Definition: resource.h:25
int32_t INT
Definition: typedefs.h:56
static char ** argv
Definition: ServiceArgs.c:11
#define NERR_Success
Definition: lmerr.h:5
#define IDS_CONFIG_SERVER_IDLE
Definition: resource.h:110
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define IDS_GENERIC_SYNTAX
Definition: resource.h:202
long LONG
Definition: pedump.c:60
DWORD sv102_users
Definition: lmserver.h:32
BOOL sv102_hidden
Definition: lmserver.h:34
INT __cdecl ConPrintf(IN PCON_STREAM Stream, IN LPWSTR szStr,...)
Definition: outstream.c:520
#define IDS_GENERIC_PAGE
Definition: resource.h:203
INT cmdConfig(INT argc, WCHAR **argv)
Definition: cmdConfig.c:151
#define IDS_CONFIG_SERVER_COMMENT
Definition: resource.h:104
smooth NULL
Definition: ftsmooth.c:416
#define SV_NODISC
Definition: lmserver.h:455
#define IDS_CONFIG_WORKSTATION_VERSION
Definition: resource.h:115
#define IDS_CONFIG_SERVER_HIDDEN
Definition: resource.h:107
INT __cdecl ConResPrintf(IN PCON_STREAM Stream, IN UINT uID,...)
Definition: outstream.c:781
DWORD NET_API_STATUS
Definition: ms-dtyp.idl:91
NET_API_STATUS WINAPI NetWkstaUserGetInfo(LMSTR reserved, DWORD level, PBYTE *bufptr)
Definition: wksta.c:279
#define IDS_CONFIG_TEXT
Definition: resource.h:102
#define IDS_CONFIG_SERVER_VERSION
Definition: resource.h:105
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IDS_CONFIG_SERVER_HELP_4
Definition: resource.h:24
#define IDS_CONFIG_WORKSTATION_DOMAIN
Definition: resource.h:116
#define IDS_CONFIG_HELP_1
Definition: resource.h:18
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IDS_CONFIG_SERVER_HELP_1
Definition: resource.h:21
#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:1087
NET_API_STATUS WINAPI NetWkstaGetInfo(LMSTR servername, DWORD level, LPBYTE *bufptr)
Definition: wksta.c:472
#define IDS_ERROR_NO_ERROR
Definition: resource.h:208
#define IDS_CONFIG_WORKSTATION_ACTIVE
Definition: resource.h:114
NET_API_STATUS WINAPI NetServerGetInfo(LMSTR servername, DWORD level, LPBYTE *bufptr)
Definition: srvsvc.c:369
#define IDS_CONFIG_WORKSTATION_LOGON
Definition: resource.h:117
Status
Definition: gdiplustypes.h:24
#define IDS_CONFIG_SERVER_HELP_2
Definition: resource.h:22
NET_API_STATUS WINAPI NetApiBufferFree(LPVOID Buffer)
Definition: apibuf.c:43
VOID PrintPaddedResourceString(UINT uID, INT nPaddedLength)
Definition: main.c:51
#define IDS_CONFIG_WORKSTATION_FULLNAME
Definition: resource.h:112
#define IDS_CONFIG_SERVER_NAME
Definition: resource.h:103
#define IDS_CONFIG_SERVER_SYNTAX
Definition: resource.h:20
INT ConPuts(IN PCON_STREAM Stream, IN LPWSTR szStr)
Definition: outstream.c:427
NET_API_STATUS WINAPI NetServerTransportEnum(_In_ LPWSTR servername, _In_ DWORD level, _Out_ LPBYTE *bufptr, _In_ DWORD prefmaxlen, _Out_ LPDWORD entriesread, _Out_ LPDWORD totalentries, _Inout_ LPDWORD resume_handle)
Definition: srvsvc.c:543
#define IDS_CONFIG_SERVER_HELP_3
Definition: resource.h:23
NET_API_STATUS WINAPI NetWkstaTransportEnum(LMSTR ServerName, DWORD level, PBYTE *pbuf, DWORD prefmaxlen, LPDWORD read_entries, PDWORD total_entries, PDWORD hresume)
Definition: wksta.c:221
#define StdOut
Definition: stream.h:76
static INT DisplayWorkstationConfig(VOID)
Definition: cmdConfig.c:75
#define IDS_CONFIG_HELP_2
Definition: resource.h:19
GLfloat GLfloat p
Definition: glext.h:8902
DWORD sv102_version_minor
Definition: lmserver.h:29
#define IDS_GENERIC_UNLIMITED
Definition: resource.h:201
GLuint64EXT * result
Definition: glext.h:11304
BYTE * PBYTE
Definition: pedump.c:66
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define IDS_GENERIC_YES
Definition: resource.h:195