Skip to content

Commit

Permalink
Issue #297: Manage WMI Empty Username
Browse files Browse the repository at this point in the history
* Ignored WMI Password when WMI Username isn't provided
* Added test cases.
* Tested the results using the CLI and the Agent.
  • Loading branch information
CherfaElyes committed Aug 23, 2024
1 parent f59bb1c commit ef1e3b3
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public List<List<String>> executeWmi(
@SpanAttribute("wmi.query") @NonNull final String wbemQuery,
@SpanAttribute("wmi.namespace") @NonNull final String namespace
) throws ClientException {
final String username = wmiConfig.getUsername();
// If the username is not provided, null will be used instead of the provided password.
final char[] password = username == null ? null : wmiConfig.getPassword();

if (username == null) {
log.warn("Hostname {}. Username not provided.", hostname);
}

// Where to connect to?
// Local: namespace
// Remote: hostname\namespace
Expand All @@ -91,21 +99,15 @@ public List<List<String>> executeWmi(
"- Namespace: {}\n- Timeout: {} s\n",
hostname,
networkResource,
wmiConfig.getUsername(),
username,
wbemQuery,
namespace,
wmiConfig.getTimeout()
)
);

// Go!
try (
WmiWbemServices wbemServices = WmiWbemServices.getInstance(
networkResource,
wmiConfig.getUsername(),
wmiConfig.getPassword()
)
) {
try (WmiWbemServices wbemServices = WmiWbemServices.getInstance(networkResource, username, password)) {
final long startTime = System.currentTimeMillis();

// Execute the WQL and get the result
Expand All @@ -125,7 +127,7 @@ public List<List<String>> executeWmi(
"- Namespace: {}\n- Timeout: {} s\n- Result:\n{}\n- response-time: {}\n",
hostname,
networkResource,
wmiConfig.getUsername(),
username,
wbemQuery,
namespace,
wmiConfig.getTimeout(),
Expand Down Expand Up @@ -270,11 +272,18 @@ public String executeWinRemoteCommand(
String command,
List<String> embeddedFiles
) throws ClientException {
final String username = winConfiguration.getUsername();
// If the username is not provided, null will be used instead of the provided password.
final char[] password = username == null ? null : winConfiguration.getPassword();

if (username == null) {
log.warn("Hostname {}. Username not provided.", hostname);
}
return executeWmiRemoteCommand(
command,
hostname,
winConfiguration.getUsername(),
winConfiguration.getPassword(),
username,
password,
winConfiguration.getTimeout().intValue(),
embeddedFiles
);
Expand Down

0 comments on commit ef1e3b3

Please sign in to comment.