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( 13 PSERVER_INFO_102 ServerInfo) 14 { 15 PSERVER_TRANSPORT_INFO_0 TransportInfo = NULL; 16 DWORD dwRead, dwTotal, i; 17 INT nPaddedLength = 38; 18 NET_API_STATUS Status; 19 20 Status = NetServerTransportEnum(NULL, 0, (PBYTE*)&TransportInfo, 21 MAX_PREFERRED_LENGTH, 22 &dwRead, 23 &dwTotal, 24 NULL); 25 if (Status != NERR_Success) 26 goto done; 27 28 PrintPaddedMessageString(4481, nPaddedLength); 29 ConPrintf(StdOut, L"\\\\%s\n", ServerInfo->sv102_name); 30 31 PrintPaddedMessageString(4482, nPaddedLength); 32 ConPrintf(StdOut, L"%s\n\n", ServerInfo->sv102_comment); 33 34 PrintPaddedMessageString(4484, nPaddedLength); 35 ConPrintf(StdOut, L"%lu.%lu\n", 36 ServerInfo->sv102_version_major, 37 ServerInfo->sv102_version_minor); 38 39 PrintPaddedMessageString(4489, nPaddedLength); 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 49 PrintPaddedMessageString(4492, nPaddedLength); 50 PrintMessageString((ServerInfo->sv102_hidden == SV_HIDDEN) ? 4300 : 4301); 51 ConPuts(StdOut, L"\n"); 52 53 PrintPaddedMessageString(4506, nPaddedLength); 54 ConPrintf(StdOut, L"%lu\n", ServerInfo->sv102_users); 55 56 PrintPaddedMessageString(4511, nPaddedLength); 57 ConPuts(StdOut, L"...\n\n"); 58 59 PrintPaddedMessageString(4520, nPaddedLength); 60 if (ServerInfo->sv102_disc == SV_NODISC) 61 PrintMessageString(4306); 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 75 DisplayWorkstationConfig(VOID) 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; 82 NET_API_STATUS Status; 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, 95 MAX_PREFERRED_LENGTH, 96 &dwRead, 97 &dwTotal, 98 NULL); 99 if (Status != NERR_Success) 100 goto done; 101 102 PrintPaddedMessageString(4450, nPaddedLength); 103 ConPrintf(StdOut, L"\\\\%s\n", WorkstationInfo->wki100_computername); 104 105 PrintPaddedMessageString(4468, nPaddedLength); 106 ConPuts(StdOut, L"...\n"); 107 108 PrintPaddedMessageString(4451, nPaddedLength); 109 ConPrintf(StdOut, L"%s\n", UserInfo->wkui1_username); 110 111 ConPuts(StdOut, L"\n"); 112 113 PrintPaddedMessageString(4453, nPaddedLength); 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 123 PrintPaddedMessageString(4452, nPaddedLength); 124 ConPrintf(StdOut, L"%lu.%lu\n", 125 WorkstationInfo->wki100_ver_major, 126 WorkstationInfo->wki100_ver_minor); 127 128 ConPuts(StdOut, L"\n"); 129 130 PrintPaddedMessageString(4455, nPaddedLength); 131 ConPrintf(StdOut, L"%s\n", WorkstationInfo->wki100_langroup); 132 133 PrintPaddedMessageString(4469, nPaddedLength); 134 ConPuts(StdOut, L"...\n"); 135 136 PrintPaddedMessageString(4456, nPaddedLength); 137 ConPrintf(StdOut, L"%s\n", UserInfo->wkui1_logon_domain); 138 139 ConPuts(StdOut, L"\n"); 140 141 PrintPaddedMessageString(4458, nPaddedLength); 142 ConPuts(StdOut, L"...\n"); 143 144 PrintPaddedMessageString(4459, nPaddedLength); 145 ConPuts(StdOut, L"...\n"); 146 147 PrintPaddedMessageString(4460, nPaddedLength); 148 ConPuts(StdOut, L"...\n"); 149 150 done: 151 if (TransportInfo != NULL) 152 NetApiBufferFree(TransportInfo); 153 154 if (UserInfo != NULL) 155 NetApiBufferFree(UserInfo); 156 157 if (WorkstationInfo != NULL) 158 NetApiBufferFree(WorkstationInfo); 159 160 return 0; 161 } 162 163 164 INT 165 cmdConfig( 166 INT argc, 167 WCHAR **argv) 168 { 169 INT i, result = 0; 170 BOOL bServer = FALSE; 171 BOOL bWorkstation = FALSE; 172 PWSTR p, endptr; 173 BOOL bModify = FALSE; 174 LONG lValue; 175 PSERVER_INFO_102 ServerInfo = NULL; 176 NET_API_STATUS Status; 177 178 for (i = 2; i < argc; i++) 179 { 180 if (_wcsicmp(argv[i], L"server") == 0) 181 { 182 if (bWorkstation == FALSE) 183 bServer = TRUE; 184 continue; 185 } 186 187 if (_wcsicmp(argv[i], L"workstation") == 0) 188 { 189 if (bServer == FALSE) 190 bWorkstation = TRUE; 191 continue; 192 } 193 194 if (_wcsicmp(argv[i], L"help") == 0) 195 { 196 /* Print short syntax help */ 197 if (bServer == TRUE) 198 { 199 PrintMessageString(4381); 200 ConPuts(StdOut, L"\n"); 201 PrintNetMessage(MSG_CONFIG_SERVER_SYNTAX); 202 } 203 else 204 { 205 PrintMessageString(4381); 206 ConPuts(StdOut, L"\n"); 207 PrintNetMessage(MSG_CONFIG_SYNTAX); 208 } 209 return 0; 210 } 211 212 if (_wcsicmp(argv[i], L"/help") == 0) 213 { 214 /* Print full help text*/ 215 if (bServer == TRUE) 216 { 217 PrintMessageString(4381); 218 ConPuts(StdOut, L"\n"); 219 PrintNetMessage(MSG_CONFIG_SERVER_SYNTAX); 220 PrintNetMessage(MSG_CONFIG_SERVER_HELP); 221 } 222 else 223 { 224 PrintMessageString(4381); 225 ConPuts(StdOut, L"\n"); 226 PrintNetMessage(MSG_CONFIG_SYNTAX); 227 PrintNetMessage(MSG_CONFIG_HELP); 228 } 229 return 0; 230 } 231 } 232 233 if (bServer) 234 { 235 Status = NetServerGetInfo(NULL, 102, (PBYTE*)&ServerInfo); 236 if (Status != NERR_Success) 237 goto done; 238 239 for (i = 2; i < argc; i++) 240 { 241 if (argv[i][0] != L'/') 242 continue; 243 244 if (_wcsnicmp(argv[i], L"/autodisconnect:", 16) == 0) 245 { 246 p = &argv[i][16]; 247 lValue = wcstol(p, &endptr, 10); 248 if (*endptr != 0) 249 { 250 PrintMessageStringV(3952, L"/AUTODISCONNECT"); 251 result = 1; 252 goto done; 253 } 254 255 if (lValue < -1 || lValue > 65535) 256 { 257 PrintMessageStringV(3952, L"/AUTODISCONNECT"); 258 result = 1; 259 goto done; 260 } 261 262 ServerInfo->sv102_disc = lValue; 263 bModify = TRUE; 264 } 265 else if (_wcsnicmp(argv[i], L"/srvcomment:", 12) == 0) 266 { 267 ServerInfo->sv102_comment = &argv[i][12]; 268 bModify = TRUE; 269 } 270 else if (_wcsnicmp(argv[i], L"/hidden:", 8) == 0) 271 { 272 p = &argv[i][8]; 273 if (_wcsicmp(p, L"yes") != 0 && _wcsicmp(p, L"no") != 0) 274 { 275 PrintMessageStringV(3952, L"/HIDDEN"); 276 result = 1; 277 goto done; 278 } 279 280 ServerInfo->sv102_hidden = (_wcsicmp(p, L"yes") == 0) ? TRUE : FALSE; 281 bModify = TRUE; 282 } 283 else 284 { 285 PrintMessageString(4381); 286 ConPuts(StdOut, L"\n"); 287 PrintNetMessage(MSG_CONFIG_SERVER_SYNTAX); 288 result = 1; 289 goto done; 290 } 291 } 292 293 if (bModify) 294 { 295 Status = NetServerSetInfo(NULL, 102, (PBYTE)&ServerInfo, NULL); 296 if (Status != NERR_Success) 297 result = 1; 298 } 299 else 300 { 301 result = DisplayServerConfig(ServerInfo); 302 } 303 } 304 else if (bWorkstation) 305 { 306 result = DisplayWorkstationConfig(); 307 } 308 else 309 { 310 PrintMessageString(4378); 311 ConPuts(StdOut, L"\n"); 312 ConPuts(StdOut, L" Server\n"); 313 ConPuts(StdOut, L" Workstation\n"); 314 ConPuts(StdOut, L"\n"); 315 } 316 317 done: 318 if (ServerInfo != NULL) 319 NetApiBufferFree(ServerInfo); 320 321 if (result == 0) 322 PrintErrorMessage(ERROR_SUCCESS); 323 324 return result; 325 } 326