Module: check_mk
Branch: master
Commit: e9e095f48d4f7f6c6995c4d3b175691936949130
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=e9e095f48d4f7f…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Fri Feb 12 10:15:13 2016 +0100
#3072 FIX windows agent: agent can now handle utf-16 encoded output from plugins
utf-16 is the default unicode encoding used on windows and appears to be the only one
supported as
an output encoding for vbs scripts.
Previously the agent would print an empty string instead of the utf-16 encoded output.
For this to work the plugin/local check has to use a unicode-enabled stdout and print a
utf-16 BOM,
i.e.:
Set objStdout = fso.GetStandardStream(1, True)
objStdout.Write(chrW(&HFEFF))
---
.werks/3072 | 15 ++++++++
ChangeLog | 1 +
agents/windows/build_version | 2 +-
agents/windows/check_mk_agent-64.exe | Bin 907776 -> 908288 bytes
agents/windows/check_mk_agent-64.unversioned.exe | Bin 907776 -> 908288 bytes
agents/windows/check_mk_agent.cc | 42 +++++++++++++---------
agents/windows/check_mk_agent.exe | Bin 832000 -> 832000 bytes
agents/windows/check_mk_agent.msi | Bin 2000384 -> 2000896 bytes
agents/windows/check_mk_agent.unversioned.exe | Bin 832000 -> 832000 bytes
agents/windows/install_agent-64.exe | Bin 416904 -> 417015 bytes
agents/windows/install_agent.exe | Bin 407353 -> 407477 bytes
agents/windows/plugins/mk_inventory.vbs | 8 +++--
12 files changed, 48 insertions(+), 20 deletions(-)
diff --git a/.werks/3072 b/.werks/3072
new file mode 100644
index 0000000..ba4f312
--- /dev/null
+++ b/.werks/3072
@@ -0,0 +1,15 @@
+Title: windows agent: agent can now handle utf-16 encoded output from plugins
+Level: 1
+Component: checks
+Compatible: compat
+Version: 1.2.7i4
+Date: 1455267933
+Class: fix
+
+utf-16 is the default unicode encoding used on windows and appears to be the only one
supported as
+an output encoding for vbs scripts.
+Previously the agent would print an empty string instead of the utf-16 encoded output.
+For this to work the plugin/local check has to use a unicode-enabled stdout and print a
utf-16 BOM,
+i.e.:
+Set objStdout = fso.GetStandardStream(1, True)
+objStdout.Write(chrW(&HFEFF))
diff --git a/ChangeLog b/ChangeLog
index 02ac762..c306b1b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -272,6 +272,7 @@
* 3054 FIX: ups_modulys_battery: Fixed wrong remaining minutes in some cases
* 3055 FIX: ibm_svc_mdiskgrp: Fixed exception in case of configured thresholds...
* 3056 FIX: vms_cpu: Fixed exception when having thresholds configured
+ * 3072 FIX: windows agent: agent can now handle utf-16 encoded output from
plugins...
Multisite:
* 2684 Added icons for downloading agent data / walks of hosts...
diff --git a/agents/windows/build_version b/agents/windows/build_version
index 939b0cb..837dd96 100644
--- a/agents/windows/build_version
+++ b/agents/windows/build_version
@@ -1 +1 @@
-1233
+1258
diff --git a/agents/windows/check_mk_agent-64.exe b/agents/windows/check_mk_agent-64.exe
index 5ffab7b..4037e7a 100755
Binary files a/agents/windows/check_mk_agent-64.exe and
b/agents/windows/check_mk_agent-64.exe differ
diff --git a/agents/windows/check_mk_agent-64.unversioned.exe
b/agents/windows/check_mk_agent-64.unversioned.exe
index 4e864d9..a8dbb2c 100755
Binary files a/agents/windows/check_mk_agent-64.unversioned.exe and
b/agents/windows/check_mk_agent-64.unversioned.exe differ
diff --git a/agents/windows/check_mk_agent.cc b/agents/windows/check_mk_agent.cc
index 082538a..e7522c3 100644
--- a/agents/windows/check_mk_agent.cc
+++ b/agents/windows/check_mk_agent.cc
@@ -2047,17 +2047,16 @@ char *add_interpreter(char *path, char *newpath) {
// -> Get-ExecutionPolicy / Set-ExecutionPolicy
//
// actually, microsoft always installs the powershell interpreter to the
- // same
- // directory (independent of the version) so even if it's not in the
- // path,
- // we have a good chance with this fallback.
+ // same directory (independent of the version) so even if it's not in
+ // the path, we have a good chance with this fallback.
+ const char *fallback =
+ "C:\\Windows\\System32\\WindowsPowershell\\v1.0\\powershell.exe";
+
char dummy;
::SearchPathA(NULL, "powershell.exe", NULL, 1, &dummy, NULL);
const char *interpreter = ::GetLastError() != ERROR_FILE_NOT_FOUND
? "powershell.exe"
- : "C:"
-
"\\Windows\\System32\\WindowsPowershell"
- "\\v1.0\\powershell.exe";
+ : fallback;
snprintf(newpath, 256,
"%s -NoLogo -ExecutionPolicy RemoteSigned \"&
\'%s\'\"",
interpreter, path);
@@ -2230,6 +2229,18 @@ int launch_program(script_container *cont) {
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
+ // if the output has a utf-16 bom, we need to convert it now, as the remaining
+ // code doesn't handle wide characters
+ unsigned char *buf_u = reinterpret_cast<unsigned char
*>(cont->buffer_work);
+ if ((buf_u[0] == 0xFF) && (buf_u[1] == 0xFE)) {
+ wchar_t *buffer_u16 = reinterpret_cast<wchar_t *>(cont->buffer_work);
+ std::string buffer_u8 = to_utf8(buffer_u16);
+ HeapFree(GetProcessHeap(), 0, buffer_u16);
+ cont->buffer_work =
+ (char *)HeapAlloc(GetProcessHeap(), 0, buffer_u8.size() + 1);
+ memcpy(cont->buffer_work, buffer_u8.c_str(), buffer_u8.size() + 1);
+ }
+
return exit_code;
}
@@ -2341,16 +2352,13 @@ void output_external_programs(OutputProxy &out, script_type
type) {
cont->buffer = NULL;
}
- // Replace BOM for UTF-16 LE and UTF-8 with newlines
- if ((strlen(cont->buffer_work)) >= 2 &&
- ((unsigned char)cont->buffer_work[0] == 0xFF &&
- (unsigned char)cont->buffer_work[1] == 0xFE)) {
- cont->buffer_work[0] = '\n';
- cont->buffer_work[1] = '\n';
- } else if (strlen(cont->buffer_work) >= 3 &&
- (unsigned char)cont->buffer_work[0] == 0xEF &&
- (unsigned char)cont->buffer_work[1] == 0xBB &&
- (unsigned char)cont->buffer_work[2] == 0xBF) {
+ // Replace BOM with newlines.
+ // At this point the buffer must not contain a wide character
+ // encoding as the code can't handle it!
+ if (strlen(cont->buffer_work) >= 3 &&
+ (unsigned char)cont->buffer_work[0] == 0xEF &&
+ (unsigned char)cont->buffer_work[1] == 0xBB &&
+ (unsigned char)cont->buffer_work[2] == 0xBF) {
cont->buffer_work[0] = '\n';
cont->buffer_work[1] = '\n';
cont->buffer_work[2] = '\n';
diff --git a/agents/windows/check_mk_agent.exe b/agents/windows/check_mk_agent.exe
index 2b81fa5..54559eb 100755
Binary files a/agents/windows/check_mk_agent.exe and b/agents/windows/check_mk_agent.exe
differ
diff --git a/agents/windows/check_mk_agent.msi b/agents/windows/check_mk_agent.msi
index 95d0461..428f210 100755
Binary files a/agents/windows/check_mk_agent.msi and b/agents/windows/check_mk_agent.msi
differ
diff --git a/agents/windows/check_mk_agent.unversioned.exe
b/agents/windows/check_mk_agent.unversioned.exe
index 22c2986..ab45e69 100755
Binary files a/agents/windows/check_mk_agent.unversioned.exe and
b/agents/windows/check_mk_agent.unversioned.exe differ
diff --git a/agents/windows/install_agent-64.exe b/agents/windows/install_agent-64.exe
index 8b18ba5..b2931d7 100755
Binary files a/agents/windows/install_agent-64.exe and
b/agents/windows/install_agent-64.exe differ
diff --git a/agents/windows/install_agent.exe b/agents/windows/install_agent.exe
index 9ad7b41..6c0da5e 100755
Binary files a/agents/windows/install_agent.exe and b/agents/windows/install_agent.exe
differ
diff --git a/agents/windows/plugins/mk_inventory.vbs
b/agents/windows/plugins/mk_inventory.vbs
index 190118a..929bded 100644
--- a/agents/windows/plugins/mk_inventory.vbs
+++ b/agents/windows/plugins/mk_inventory.vbs
@@ -10,7 +10,8 @@ exePaths = Array("")
regPaths =
Array("Software\Microsoft\Windows\CurrentVersion\Uninstall","Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall")
Set fso = CreateObject("Scripting.FileSystemObject")
-Set objStdout = WScript.Stdout
+' request unicode stdout
+Set objStdout = fso.GetStandardStream(1, True)
Set objClass =
GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set wshShell = WScript.CreateObject( "WScript.Shell" )
remote_host = wshShell.ExpandEnvironmentStrings( "%REMOTE_HOST%" )
@@ -47,12 +48,15 @@ End If
' handle error message ourselves so this script can also be run directly, for
testing
On Error Resume Next
+'need a bom so the agent knows we send utf-16
+outPut(chrW(&HFEFF))
+
' create new timestamp file
' only allowed when script runs as administrator user
Set stampo = fso.CreateTextFile(timestamp)
If Err.Number <> 0 Then
- outPut "Failed to create time stamp: " & Err.Description & "
(" & Err.Number & ")"
+ outPut "Failed to create time stamp: " & Err.Description & "
(" & Err.Number & ")"
Err.Clear
End If