summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Smith <tsmith@chef.io>2018-09-14 10:53:51 -0700
committerGitHub <noreply@github.com>2018-09-14 10:53:51 -0700
commite498eac89560647ebeb5097fc2af58f53aedd22f (patch)
tree5d439c207392c40c8b779d3479abf7115024f9e2
parent3ec3c328c5c8c93601761bf6444964b4f24c6bb9 (diff)
parentdaffcbbfac0d110afd80dd7e162b92d458a67183 (diff)
downloadohai-e498eac89560647ebeb5097fc2af58f53aedd22f.tar.gz
Merge pull request #1240 from jugatsu/fix-root-group-plugin-on-localized
Fix root_group plugin invalid byte sequence on non-English version of Windows
-rw-r--r--lib/ohai/plugins/root_group.rb15
-rw-r--r--lib/ohai/util/win32/group_helper.rb3
-rw-r--r--spec/unit/plugins/root_group_spec.rb16
3 files changed, 28 insertions, 6 deletions
diff --git a/lib/ohai/plugins/root_group.rb b/lib/ohai/plugins/root_group.rb
index 04fb6412..ea1af938 100644
--- a/lib/ohai/plugins/root_group.rb
+++ b/lib/ohai/plugins/root_group.rb
@@ -19,8 +19,19 @@ Ohai.plugin(:RootGroup) do
provides "root_group"
collect_data(:windows) do
- require "ohai/util/win32/group_helper"
- root_group Ohai::Util::Win32::GroupHelper.windows_root_group_name
+ require "wmi-lite/wmi"
+
+ wmi = WmiLite::Wmi.new
+ # Per http://support.microsoft.com/kb/243330 SID: S-1-5-32-544 is the
+ # internal name for the Administrators group, which lets us work
+ # properly in environments with a renamed or localized name for the
+ # Administrators group.
+ # Use LocalAccount=True because otherwise WMI will attempt to include
+ # (unneeded) Active Directory groups by querying AD, which is a performance
+ # and reliability issue since AD might not be reachable.
+ groups = wmi.query("select * from Win32_Group where sid like 'S-1-5-32-544' and LocalAccount=True")
+ windows_root_group_name = groups[0]["name"]
+ root_group windows_root_group_name
end
collect_data(:default) do
diff --git a/lib/ohai/util/win32/group_helper.rb b/lib/ohai/util/win32/group_helper.rb
index 0abc1db7..ecf4a489 100644
--- a/lib/ohai/util/win32/group_helper.rb
+++ b/lib/ohai/util/win32/group_helper.rb
@@ -21,6 +21,7 @@ require "ohai/util/win32"
module Ohai
module Util
class Win32::GroupHelper
+ # @deprecated
# Per http://support.microsoft.com/kb/243330 SID: S-1-5-32-544 is the
# internal name for the Administrators group, which lets us work
@@ -29,6 +30,8 @@ module Ohai
BUILTIN_ADMINISTRATORS_SID = "S-1-5-32-544".freeze
def self.windows_root_group_name
+ warn "The 'windows_root_group_name' helper is deprecated and will be removed in Ohai 15. Please update your plugins to remove this helper method."
+
administrators_sid_result = FFI::MemoryPointer.new(:pointer)
convert_result = Win32.convert_string_sid_to_sid(BUILTIN_ADMINISTRATORS_SID, administrators_sid_result)
last_win32_error = Win32.get_last_error
diff --git a/spec/unit/plugins/root_group_spec.rb b/spec/unit/plugins/root_group_spec.rb
index 8289a296..4ac2a2b0 100644
--- a/spec/unit/plugins/root_group_spec.rb
+++ b/spec/unit/plugins/root_group_spec.rb
@@ -17,7 +17,6 @@
#
require_relative "../../spec_helper.rb"
-require "ohai/util/win32/group_helper"
describe Ohai::System, "root_group" do
before(:each) do
@@ -78,11 +77,20 @@ describe Ohai::System, "root_group" do
end
describe "windows platform" do
- it "should return the group administrators" do
+
+ let(:wmi) { double("wmi", { query: "" }) }
+
+ before(:each) do
+ allow(WmiLite::Wmi).to receive(:new).and_return(wmi)
allow(@plugin).to receive(:collect_os).and_return(:windows)
- expect(Ohai::Util::Win32::GroupHelper).to receive(:windows_root_group_name).and_return("administrators")
+ end
+ it "should return the group Administrators" do
+ expect(wmi)
+ .to receive(:query)
+ .with("select * from Win32_Group where sid like 'S-1-5-32-544' and LocalAccount=True")
+ .and_return("Administrators")
+
@plugin.run
- expect(@plugin[:root_group]).to eq("administrators")
end
end
end