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
12 DisplayServerConfig(VOID)
13 {
14     PSERVER_INFO_102 ServerInfo = NULL;
15     PSERVER_TRANSPORT_INFO_0 TransportInfo = NULL;
16     DWORD dwRead, dwTotal, i;
17     INT nPaddedLength = 38;
18     NET_API_STATUS Status;
19 
20     Status = NetServerGetInfo(NULL, 102, (PBYTE*)&ServerInfo);
21     if (Status != NERR_Success)
22         goto done;
23 
24     Status = NetServerTransportEnum(NULL, 0, (PBYTE*)&TransportInfo,
25                                     MAX_PREFERRED_LENGTH,
26                                     &dwRead,
27                                     &dwTotal,
28                                     NULL);
29     if (Status != NERR_Success)
30         goto done;
31 
32     PrintPaddedResourceString(IDS_CONFIG_SERVER_NAME, nPaddedLength);
33     ConPrintf(StdOut, L"\\\\%s\n", ServerInfo->sv102_name);
34 
35     PrintPaddedResourceString(IDS_CONFIG_SERVER_COMMENT, nPaddedLength);
36     ConPrintf(StdOut, L"%s\n\n", ServerInfo->sv102_comment);
37 
38     PrintPaddedResourceString(IDS_CONFIG_SERVER_VERSION, nPaddedLength);
39     ConPrintf(StdOut, L"%lu.%lu\n",
40               ServerInfo->sv102_version_major,
41               ServerInfo->sv102_version_minor);
42 
43     ConResPuts(StdOut, IDS_CONFIG_SERVER_ACTIVE);
44     ConPuts(StdOut, L"\n");
45     for (i = 0; i < dwRead; i++)
46     {
47         ConPrintf(StdOut, L"      %s (%s)\n",
48                   &TransportInfo[i].svti0_transportname[8],
49                   TransportInfo[i].svti0_networkaddress);
50     }
51     ConPuts(StdOut, L"\n");
52 
53     PrintPaddedResourceString(IDS_CONFIG_SERVER_HIDDEN, nPaddedLength);
54     ConResPuts(StdOut, (ServerInfo->sv102_hidden == SV_HIDDEN) ? IDS_GENERIC_YES : IDS_GENERIC_NO);
55     ConPuts(StdOut, L"\n");
56 
57     PrintPaddedResourceString(IDS_CONFIG_SERVER_USERS, nPaddedLength);
58     ConPrintf(StdOut, L"%lu\n", ServerInfo->sv102_users);
59 
60     PrintPaddedResourceString(IDS_CONFIG_SERVER_FILES, nPaddedLength);
61     ConPuts(StdOut, L"...\n\n");
62 
63     PrintPaddedResourceString(IDS_CONFIG_SERVER_IDLE, nPaddedLength);
64     if (ServerInfo->sv102_disc == SV_NODISC)
65         ConResPuts(StdOut, IDS_GENERIC_UNLIMITED);
66     else
67         ConPrintf(StdOut, L"%lu\n", ServerInfo->sv102_disc);
68 
69 done:
70     if (TransportInfo != NULL)
71         NetApiBufferFree(TransportInfo);
72 
73     if (ServerInfo != NULL)
74         NetApiBufferFree(ServerInfo);
75 
76     return 0;
77 }
78 
79 
80 static
81 INT
82 DisplayWorkstationConfig(VOID)
83 {
84     PWKSTA_INFO_100 WorkstationInfo = NULL;
85     PWKSTA_USER_INFO_1 UserInfo = NULL;
86     PWKSTA_TRANSPORT_INFO_0 TransportInfo = NULL;
87     DWORD dwRead = 0, dwTotal = 0, i;
88     INT nPaddedLength = 38;
89     NET_API_STATUS Status;
90 
91     Status = NetWkstaGetInfo(NULL, 100, (PBYTE*)&WorkstationInfo);
92     if (Status != NERR_Success)
93         goto done;
94 
95     Status = NetWkstaUserGetInfo(NULL, 1, (PBYTE*)&UserInfo);
96     if (Status != NERR_Success)
97         goto done;
98 
99     Status = NetWkstaTransportEnum(NULL,
100                                    0,
101                                    (PBYTE*)&TransportInfo,
102                                    MAX_PREFERRED_LENGTH,
103                                    &dwRead,
104                                    &dwTotal,
105                                    NULL);
106     if (Status != NERR_Success)
107         goto done;
108 
109     PrintPaddedResourceString(IDS_CONFIG_WORKSTATION_NAME, nPaddedLength);
110     ConPrintf(StdOut, L"\\\\%s\n", WorkstationInfo->wki100_computername);
111 
112     PrintPaddedResourceString(IDS_CONFIG_WORKSTATION_FULLNAME, nPaddedLength);
113     ConPuts(StdOut, L"...\n");
114 
115     PrintPaddedResourceString(IDS_CONFIG_WORKSTATION_USERNAME, nPaddedLength);
116     ConPrintf(StdOut, L"%s\n", UserInfo->wkui1_username);
117 
118     ConPuts(StdOut, L"\n");
119 
120     ConResPuts(StdOut, IDS_CONFIG_WORKSTATION_ACTIVE);
121     ConPuts(StdOut, L"\n");
122     for (i = 0; i < dwRead; i++)
123     {
124         ConPrintf(StdOut, L"      %s (%s)\n",
125                   &TransportInfo[i].wkti0_transport_name[8],
126                   TransportInfo[i].wkti0_transport_address);
127     }
128     ConPuts(StdOut, L"\n");
129 
130     PrintPaddedResourceString(IDS_CONFIG_WORKSTATION_VERSION, nPaddedLength);
131     ConPrintf(StdOut, L"%lu.%lu\n",
132               WorkstationInfo->wki100_ver_major,
133               WorkstationInfo->wki100_ver_minor);
134 
135     ConPuts(StdOut, L"\n");
136 
137     PrintPaddedResourceString(IDS_CONFIG_WORKSTATION_DOMAIN, nPaddedLength);
138     ConPrintf(StdOut, L"%s\n", WorkstationInfo->wki100_langroup);
139 
140     PrintPaddedResourceString(IDS_CONFIG_WORKSTATION_LOGON, nPaddedLength);
141     ConPrintf(StdOut, L"%s\n", UserInfo->wkui1_logon_domain);
142 
143 done:
144     if (TransportInfo != NULL)
145         NetApiBufferFree(TransportInfo);
146 
147     if (UserInfo != NULL)
148         NetApiBufferFree(UserInfo);
149 
150     if (WorkstationInfo != NULL)
151         NetApiBufferFree(WorkstationInfo);
152 
153     return 0;
154 }
155 
156 
157 INT
158 cmdConfig(
159     INT argc,
160     WCHAR **argv)
161 {
162     INT i, result = 0;
163     BOOL bServer = FALSE;
164     BOOL bWorkstation = FALSE;
165 
166     for (i = 2; i < argc; i++)
167     {
168         if (_wcsicmp(argv[i], L"server") == 0)
169         {
170             if (bWorkstation == FALSE)
171                 bServer = TRUE;
172             continue;
173         }
174 
175         if (_wcsicmp(argv[i], L"workstation") == 0)
176         {
177             if (bServer == FALSE)
178                 bWorkstation = TRUE;
179             continue;
180         }
181 
182         if (_wcsicmp(argv[i], L"help") == 0)
183         {
184             /* Print short syntax help */
185             if (bServer == TRUE)
186             {
187                 ConResPuts(StdOut, IDS_GENERIC_SYNTAX);
188                 ConResPuts(StdOut, IDS_CONFIG_SERVER_SYNTAX);
189             }
190             else
191             {
192                 ConResPuts(StdOut, IDS_GENERIC_SYNTAX);
193                 ConResPuts(StdOut, IDS_CONFIG_SYNTAX);
194             }
195             return 0;
196         }
197 
198         if (_wcsicmp(argv[i], L"/help") == 0)
199         {
200             /* Print full help text*/
201             if (bServer == TRUE)
202             {
203                 ConResPuts(StdOut, IDS_GENERIC_SYNTAX);
204                 ConResPuts(StdOut, IDS_CONFIG_SERVER_SYNTAX);
205                 ConResPuts(StdOut, IDS_CONFIG_SERVER_HELP_1);
206                 ConResPuts(StdOut, IDS_CONFIG_SERVER_HELP_2);
207                 ConResPuts(StdOut, IDS_CONFIG_SERVER_HELP_3);
208                 ConResPuts(StdOut, IDS_CONFIG_SERVER_HELP_4);
209                 ConResPuts(StdOut, IDS_CONFIG_SERVER_HELP_5);
210                 ConResPuts(StdOut, IDS_GENERIC_PAGE);
211             }
212             else
213             {
214                 ConResPuts(StdOut, IDS_GENERIC_SYNTAX);
215                 ConResPuts(StdOut, IDS_CONFIG_SYNTAX);
216                 ConResPuts(StdOut, IDS_CONFIG_HELP_1);
217                 ConResPuts(StdOut, IDS_CONFIG_HELP_2);
218             }
219             return 0;
220         }
221     }
222 
223     if (bServer)
224     {
225         result = DisplayServerConfig();
226     }
227     else if (bWorkstation)
228     {
229         result = DisplayWorkstationConfig();
230     }
231     else
232     {
233         ConResPuts(StdOut, IDS_CONFIG_TEXT);
234     }
235 
236     if (result == 0)
237         ConResPuts(StdOut, IDS_ERROR_NO_ERROR);
238 
239     return result;
240 }