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 PrintPaddedResourceString(IDS_CONFIG_SERVER_NAME, nPaddedLength); 29 ConPrintf(StdOut, L"\\\\%s\n", ServerInfo->sv102_name); 30 31 PrintPaddedResourceString(IDS_CONFIG_SERVER_COMMENT, nPaddedLength); 32 ConPrintf(StdOut, L"%s\n\n", ServerInfo->sv102_comment); 33 34 PrintPaddedResourceString(IDS_CONFIG_SERVER_VERSION, nPaddedLength); 35 ConPrintf(StdOut, L"%lu.%lu\n", 36 ServerInfo->sv102_version_major, 37 ServerInfo->sv102_version_minor); 38 39 ConResPuts(StdOut, IDS_CONFIG_SERVER_ACTIVE); 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 PrintPaddedResourceString(IDS_CONFIG_SERVER_HIDDEN, nPaddedLength); 50 ConResPuts(StdOut, (ServerInfo->sv102_hidden == SV_HIDDEN) ? IDS_GENERIC_YES : IDS_GENERIC_NO); 51 ConPuts(StdOut, L"\n"); 52 53 PrintPaddedResourceString(IDS_CONFIG_SERVER_USERS, nPaddedLength); 54 ConPrintf(StdOut, L"%lu\n", ServerInfo->sv102_users); 55 56 PrintPaddedResourceString(IDS_CONFIG_SERVER_FILES, nPaddedLength); 57 ConPuts(StdOut, L"...\n\n"); 58 59 PrintPaddedResourceString(IDS_CONFIG_SERVER_IDLE, nPaddedLength); 60 if (ServerInfo->sv102_disc == SV_NODISC) 61 ConResPuts(StdOut, IDS_GENERIC_UNLIMITED); 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 PrintPaddedResourceString(IDS_CONFIG_WORKSTATION_NAME, nPaddedLength); 103 ConPrintf(StdOut, L"\\\\%s\n", WorkstationInfo->wki100_computername); 104 105 PrintPaddedResourceString(IDS_CONFIG_WORKSTATION_FULLNAME, nPaddedLength); 106 ConPuts(StdOut, L"...\n"); 107 108 PrintPaddedResourceString(IDS_CONFIG_WORKSTATION_USERNAME, nPaddedLength); 109 ConPrintf(StdOut, L"%s\n", UserInfo->wkui1_username); 110 111 ConPuts(StdOut, L"\n"); 112 113 ConResPuts(StdOut, IDS_CONFIG_WORKSTATION_ACTIVE); 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 PrintPaddedResourceString(IDS_CONFIG_WORKSTATION_VERSION, 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 PrintPaddedResourceString(IDS_CONFIG_WORKSTATION_DOMAIN, nPaddedLength); 131 ConPrintf(StdOut, L"%s\n", WorkstationInfo->wki100_langroup); 132 133 PrintPaddedResourceString(IDS_CONFIG_WORKSTATION_LOGON, nPaddedLength); 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 151 cmdConfig( 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; 162 NET_API_STATUS Status; 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 { 185 ConResPuts(StdOut, IDS_GENERIC_SYNTAX); 186 ConResPuts(StdOut, IDS_CONFIG_SERVER_SYNTAX); 187 } 188 else 189 { 190 ConResPuts(StdOut, IDS_GENERIC_SYNTAX); 191 ConResPuts(StdOut, IDS_CONFIG_SYNTAX); 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 { 201 ConResPuts(StdOut, IDS_GENERIC_SYNTAX); 202 ConResPuts(StdOut, IDS_CONFIG_SERVER_SYNTAX); 203 ConResPuts(StdOut, IDS_CONFIG_SERVER_HELP_1); 204 ConResPuts(StdOut, IDS_CONFIG_SERVER_HELP_2); 205 ConResPuts(StdOut, IDS_CONFIG_SERVER_HELP_3); 206 ConResPuts(StdOut, IDS_CONFIG_SERVER_HELP_4); 207 ConResPuts(StdOut, IDS_CONFIG_SERVER_HELP_5); 208 ConResPuts(StdOut, IDS_GENERIC_PAGE); 209 } 210 else 211 { 212 ConResPuts(StdOut, IDS_GENERIC_SYNTAX); 213 ConResPuts(StdOut, IDS_CONFIG_SYNTAX); 214 ConResPuts(StdOut, IDS_CONFIG_HELP_1); 215 ConResPuts(StdOut, IDS_CONFIG_HELP_2); 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 { 238 ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/AUTODISCONNECT"); 239 result = 1; 240 goto done; 241 } 242 243 if (lValue < -1 || lValue > 65535) 244 { 245 ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/AUTODISCONNECT"); 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 { 263 ConResPrintf(StdErr, IDS_ERROR_INVALID_OPTION_VALUE, L"/HIDDEN"); 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 { 273 ConResPuts(StdOut, IDS_GENERIC_SYNTAX); 274 ConResPuts(StdOut, IDS_CONFIG_SERVER_SYNTAX); 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 { 297 ConResPuts(StdOut, IDS_CONFIG_TEXT); 298 } 299 300 done: 301 if (ServerInfo != NULL) 302 NetApiBufferFree(ServerInfo); 303 304 if (result == 0) 305 ConResPuts(StdOut, IDS_ERROR_NO_ERROR); 306 307 return result; 308 }